fix: Gracefully handle event loops in fresh process - #811
Open
hneiva wants to merge 1 commit into
Open
Conversation
jcristau
requested changes
Jul 31, 2026
Comment on lines
+248
to
+251
| try: | ||
| self._event_loop = asyncio.get_running_loop() | ||
| except RuntimeError: | ||
| self._event_loop = asyncio.new_event_loop() |
Contributor
There was a problem hiding this comment.
This seems kind of awful. Can we do something consistent here instead? What do the tests actually require?
Contributor
Author
There was a problem hiding this comment.
I agree it's awful.
But it's better than if asyncio.get_event_loop_policy()._local._loop is not None
They don't have a way of checking if there is a current event loop and actually recommend this exact method 🫠
In Python 3.12/3.13 they deprecated get_event_loop() returning a new loop when none is current. In Python 3.14 it now raises a RuntimeError. Reference: https://docs.python.org/3.14/library/asyncio-eventloop.html#asyncio.get_event_loop
hneiva
force-pushed
the
hneiva/event-loop-fix
branch
from
July 31, 2026 15:44
10c3b47 to
4bc73ad
Compare
hneiva
enabled auto-merge
July 31, 2026 15:45
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In Python 3.12/3.13 they deprecated get_event_loop() returning a new loop when none is current. In Python 3.14 it now raises a RuntimeError.
Reference: https://docs.python.org/3.14/library/asyncio-eventloop.html#asyncio.get_event_loop