Skip to content

fix: Gracefully handle event loops in fresh process - #811

Open
hneiva wants to merge 1 commit into
mainfrom
hneiva/event-loop-fix
Open

fix: Gracefully handle event loops in fresh process#811
hneiva wants to merge 1 commit into
mainfrom
hneiva/event-loop-fix

Conversation

@hneiva

@hneiva hneiva commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

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
hneiva requested a review from a team as a code owner July 30, 2026 23:29
Comment thread HISTORY.rst Outdated
Comment on lines +248 to +251
try:
self._event_loop = asyncio.get_running_loop()
except RuntimeError:
self._event_loop = asyncio.new_event_loop()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This seems kind of awful. Can we do something consistent here instead? What do the tests actually require?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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
hneiva force-pushed the hneiva/event-loop-fix branch from 10c3b47 to 4bc73ad Compare July 31, 2026 15:44
@hneiva
hneiva enabled auto-merge July 31, 2026 15:45
@hneiva
hneiva requested a review from jcristau July 31, 2026 15:45
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.

2 participants