Fix Python 3.14 compatibility: replace deprecated asyncio.get_event_loop()#2831
Open
Jscoats wants to merge 1 commit intopostlund:masterfrom
Open
Fix Python 3.14 compatibility: replace deprecated asyncio.get_event_loop()#2831Jscoats wants to merge 1 commit intopostlund:masterfrom
Jscoats wants to merge 1 commit intopostlund:masterfrom
Conversation
…oop() Replace all usage of asyncio.get_event_loop() which raises RuntimeError in Python 3.14 when no event loop exists in the current thread. Changes: - CLI entry points: get_event_loop() + run_until_complete() -> asyncio.run() - Core library: get_event_loop() -> get_running_loop() in async contexts and __init__ methods called within running event loops - Remove deprecated loop= kwargs from StreamReader, ensure_future - Fix asyncio.wait() to accept set instead of list (knock.py, atvscript.py) - Modernize all examples to use asyncio.run() - Add regression test verifying CLI scripts bootstrap without pre-existing event loop - Update test conftest to match new appstart() signature Public API (scan, connect, pair) signatures are preserved. Fixes postlund#2829 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Plz merge. This issue makes it impossible to set up pyatv on 3.14. |
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
Fixes #2829 — All
pyatvCLI scripts (atvremote,atvscript,atvlog,atvproxy) crash on Python 3.14 due toasyncio.get_event_loop()raisingRuntimeErrorwhen no event loop exists in the current thread.Changes
CLI entry points (4 scripts):
main():get_event_loop()+run_until_complete()→asyncio.run()loopparameter threading, each now callsasyncio.get_running_loop()where neededCore library (10 files):
asyncio.get_event_loop()→asyncio.get_running_loop()(in__init__methods and async functions)Additional deprecation fixes:
asyncio.StreamReader(loop=loop)→asyncio.StreamReader()(param removed in 3.10)asyncio.ensure_future(..., loop=loop)→asyncio.ensure_future(...)(param removed in 3.10)asyncio.wait([list])→asyncio.wait(set(...))inknock.py(list deprecated in 3.11)Examples (9 files):
asyncio.run()instead ofget_event_loop().run_until_complete()Tests:
tests/scripts/conftest.pyto callappstart()withoutlooptest_asyncio_compat.py— regression tests verifying all 4 CLI scripts bootstrap without a pre-existing event loopWhat's NOT changed
pyatv.scan(),pyatv.connect(),pyatv.pair()) — all signatures preservedasyncio.get_running_loop()is available since Python 3.7, so this is safe across all supported versions (3.9+)Note on
asyncio.run()vsloop.run_until_complete()asyncio.run()additionally finalizes async generators and shuts down the default executor on exit, which is slightly better cleanup behavior. This has no observable effect on CLI usage.Testing
grep -rn "get_event_loop" pyatv/ examples/returns zero matches