Skip to content

fix asyncio deprecation warning#259

Draft
ekenyon676 wants to merge 2 commits into
gvalkov:mainfrom
ekenyon676:fix_async_deprecation
Draft

fix asyncio deprecation warning#259
ekenyon676 wants to merge 2 commits into
gvalkov:mainfrom
ekenyon676:fix_async_deprecation

Conversation

@ekenyon676

Copy link
Copy Markdown

Summary

eventio_async.py relies 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 the aync_read_* methods.

  • asyncio.Future() — implicitly binds to the current loop via get_event_loop().
  • asyncio.get_event_loop() — emits a DeprecationWarning on 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 on self._loop so close() 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. Normal async for / await usage 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, and async_read), and confirmed the deprecation warnings no longer appear and events are read properly.

Comment thread src/evdev/eventio_async.py Outdated
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