Skip to content

Wrap examples in async with connection: for Python 3.14#61

Open
ulvs wants to merge 1 commit into
qrt_async_context_managerfrom
examples_use_async_with
Open

Wrap examples in async with connection: for Python 3.14#61
ulvs wants to merge 1 commit into
qrt_async_context_managerfrom
examples_use_async_with

Conversation

@ulvs

@ulvs ulvs commented Jun 11, 2026

Copy link
Copy Markdown
Member

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 to asyncio.run(main()) throughout — loop.run_forever no longer composes with the new context-managed connection scope.

  • basic_example.py: stream_frames returns after registering its callback, so the new 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.

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>
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.

1 participant