Wrap examples in async with connection: for Python 3.14#61
Open
ulvs wants to merge 1 commit into
Open
Conversation
QRTConnection is an async context manager since the previous commit; this PR actually wraps each example body in it, so the TCP transport is closed deterministically on scope exit rather than at GC time. Under Python 3.14 this eliminates the ResourceWarning each example produced on exit. Several examples also still used pre-3.14 entry points (`asyncio.ensure_future + run_forever`, `asyncio.get_event_loop() .run_until_complete`). Switched to `asyncio.run(main())` in all of them, since `loop.run_forever` no longer composes with the new context-managed connection scope. basic_example.py: `stream_frames` returns after registering the on_packet callback, so the new `async with connection:` block explicitly awaits `asyncio.Event()` to keep the connection alive. advanced_example.py: replaced `loop.stop()` shutdown signal with an `asyncio.Event` that main() awaits. Verified end-to-end against QTM 2026.3 Beta on Python 3.14: all seven examples shut down without ResourceWarning. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Depends on #59.
QRTConnection is an async context manager since #59; this PR wraps each example body in it so the TCP transport closes deterministically. Eliminates the
ResourceWarnings each example produced on Python 3.14 exit.Several examples also still used pre-3.14 entry points (
asyncio.ensure_future + run_forever,asyncio.get_event_loop().run_until_complete). Switched toasyncio.run(main())throughout —loop.run_foreverno longer composes with the new context-managed connection scope.basic_example.py:stream_framesreturns after registering its callback, so the new block explicitly awaitsasyncio.Event()to keep the connection alive.advanced_example.py: replacedloop.stop()shutdown signal with anasyncio.Eventthatmain()awaits.Verified end-to-end against QTM 2026.3 Beta on Python 3.14: all seven examples shut down without
ResourceWarning.