fix asyncio deprecation warning#259
Draft
ekenyon676 wants to merge 2 commits into
Draft
Conversation
sezanzeb
reviewed
Jul 15, 2026
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.
Summary
eventio_async.pyrelies on two asyncio APIs that are deprecated when called without a running event loop, and will emit a DeprecationWarning on any code that doesn't use theaync_read_*methods.asyncio.Future()— implicitly binds to the current loop viaget_event_loop().asyncio.get_event_loop()— emits aDeprecationWarningon Python 3.10+ (and is slated for removal) when there is no running loop.Replaced with:
asyncio.get_running_loop().create_future()for creating futures (ReadIterator.__anext__,async_read_one,async_read).asyncio.get_running_loop()in_do_when_readable, caching the loop onself._loopsoclose()can later remove the reader from the exact loop it was registered on.Behavior change
The old code tolerated building a read future before any loop was running. The new code must now be called from within a running loop, otherwise it will raise
RuntimeError: no running event loop. Normalasync for/awaitusage inside a coroutine is unaffected. I looked around at how this code is used in public repos (notably Home Assistant), and it appeared that nothing would break.Testing
I wrote up a couple of example scripts (reading events via
async_read_loop,async_read_one, andasync_read), and confirmed the deprecation warnings no longer appear and events are read properly.