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

Modernize event loop behavior #387

Merged
merged 8 commits into from Jan 3, 2024
Merged

Conversation

blink1073
Copy link
Member

@blink1073 blink1073 commented Dec 31, 2023

Based on discussion in python/cpython#100160, we should not be relying on asyncio.get_event_loop, since they are in fact going to make it an alias for asyncio.get_running_loop.

This ensures we install an event loop before launching our apps, so we should not see any more issues like jupyter/notebook#6721.

Additionally, it adds a new class, JupyterAsyncApp that runs initialize_async() and start_async() in an event loop.

Based on results in ipython/ipykernel#1184, we'll want to normally use the default event loop on Windows, unless we know we're running a tornado app. This PR adds a prefer_selector_loop option to ensure_event_loop so we can override _prefer_selector_loop in jupyter_server apps to prefer the selector loop.

Based on failures seen in #383, we add tests to ensure we are not interfering with existing event loop behavior.

Copy link

@gvanrossum gvanrossum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you name it something other than ‘get_event_loop’, to avoid confusion with the asyncio function by that name? Maybe ‘ensure_event_loop’?

@blink1073
Copy link
Member Author

Could you name it something other than ‘get_event_loop’, to avoid confusion with the asyncio function by that name? Maybe ‘ensure_event_loop’?

Done, thank you!

@blink1073 blink1073 enabled auto-merge (squash) January 3, 2024 15:26
@blink1073 blink1073 merged commit 19912f4 into jupyter:main Jan 3, 2024
29 checks passed
@blink1073 blink1073 deleted the better-asyncio branch January 3, 2024 16:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants