Skip to content

Commit

Permalink
Use get_running_loop() instead of get_event_loop()
Browse files Browse the repository at this point in the history
This PR proposes to change get_event_loop() to get_running_loop() in `prompt_toolkit/application.py` to improve compatibility on Windows.

As mentioned in other places of the prompt_toolkit codebase, get_running_loop() is the recommended way to get the event loop since Python 3.7, because it returns the running loop for the current context instead of strictly the default loop.

This is important for prompt_toolkit to work properly on Windows, where the default loop may not be compatible. Using get_running_loop() can avoid potential issues with an incompatible default loop.

The usage of get_event_loop() in `prompt_toolkit/application.py` seems to be leftover from early development, and was likely forgotten to be changed when adding Windows support. All other occurrences have been updated to `use get_running_loop()`.

Replacing this instance of get_event_loop() with get_running_loop() should improve portability without introducing side effects. It follows the prompting_toolkit's design goal of being cross-platform compatible.

Therefore, I propose we make this change to remain consistent with the rest of the codebase and avoid potential bugs on Windows. Please consider merging this PR to use get_running_loop() instead of get_event_loop() in application.py. Let me know if any changes are necessary. Thanks!
  • Loading branch information
jiaosenvip authored Jul 29, 2023
1 parent 490cf90 commit a908ba2
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/prompt_toolkit/application/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -958,7 +958,7 @@ def run_in_thread() -> None:
# See whether a loop was installed already. If so, use that. That's
# required for the input hooks to work, they are installed using
# `set_event_loop`.
loop = asyncio.get_event_loop()
loop = asyncio.get_running_loop()
except RuntimeError:
# No loop installed. Run like usual.
return asyncio.run(coro)
Expand Down

0 comments on commit a908ba2

Please sign in to comment.