Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use get_running_loop instead of get_event_loop #1823

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

auxsvr
Copy link

@auxsvr auxsvr commented Dec 7, 2023

The latter is deprecated and may not always return the running event loop.

Resolves #1824.

The latter is deprecated and may not always return the running event loop.
@jonathanslenders
Copy link
Member

This is intentional. IPython used to pass the input hook by setting an event loop which we can use in prompt_toolkit.

The if _called_from_ipython(): test that we have there is a workaround to ensure that %gui keeps working in older IPython versions. Merging this would break those IPython versions.

We can remove the elif _called_from_ipython(): block entirely when everyone who's using the newest prompt_toolkit also uses the newest IPython. Or we should check the IPython version in the called_from_ipython() function and return False for the newer IPython versions.

Feel free to create a PR that does that.

@auxsvr
Copy link
Author

auxsvr commented Dec 7, 2023

asyncio.get_event_loop is already deprecated and may not return the running loop, cf. python/cpython#96377 (comment). According to the discussion there, it should be replaced with asyncio.get_running_loop or the corresponding policy method. If the loop on line 988 is the running loop, this should not break old versions (newer than Python 3.7), if I understand the purpose of this code correctly. Of course, as I am not familiar with the codebase, I could be wrong.

@auxsvr
Copy link
Author

auxsvr commented Dec 12, 2023

If I am wrong, please explain. At the moment, using asyncio.get_running_loop looks like the easiest option to me, preserving backward compatibility.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RuntimeError: This event loop is already running
2 participants