Repository navigation
Support Python WinRT operations in asyncio tasks - #130
Merged
Merged
Conversation
Mixed-language test coverageWorkflow status: ✅ Passed
|
Shawn Yuan (shuaiyuanxx)
approved these changes
Sep 3, 2026
Implement the coroutine driving protocol for generated WinRT async operations while preserving repeatable direct awaits, cancellation, progress, blocking safeguards, and release semantics. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Handle throw injection before asyncio owner resolution, close the coroutine protocol synchronously, and preserve WinRT cancellation cleanup failures. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Keep the existing WinRTAsync contracts structurally compatible while exposing dedicated coroutine return protocols for generated asyncio task inputs. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
leileizhang (lei9444)
force-pushed
the
lei9444-async-create-task
branch
from
September 3, 2026 07:07
017d0b6 to
9778588
Compare
Deactivate native and queued progress dispatch captures when coroutine execution finishes, is cancelled, or is released so late WinRT callbacks cannot retain observers or target a closed event loop. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Shawn Yuan (shuaiyuanxx)
approved these changes
Sep 3, 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.
Closes #126
Summary
asyncio.create_task()andTaskGroup.create_task()accept them directlyWinRTAsync[T]andWinRTAsyncWithProgress[T, P]protocols for backward compatibility with mocks and adaptersWinRTCoroutine[T]andWinRTCoroutineWithProgress[T, P]return protocols that combine the legacy WinRT operation surface withcollections.abc.Coroutine_DynWinRTAsyncimplementations withcollections.abc.Coroutineat runtimeensure_future(),wait_for(), result conversion, failures, and cancellationthrow(), andclose()statesIAsyncInfo.Cancel, WinRT cancellation asasyncio.CancelledError, progress callbacks, blockingwait()safeguards, and idempotentrelease()close(), andrelease()so late WinRT notifications cannot retain observers or target a closed event loopDesign
asyncio.Taskdrives accepted objects throughsend()andthrow()rather than__await__(). The runtime therefore delegates those methods to a real Python bridge coroutine while keeping__await__()backed by the existing cached asyncio future. This preserves repeatable direct awaits without pretending the task-driving coroutine itself is reusable. Concurrent or repeated task-driving attempts fail deterministically with native-coroutine-style errors.The lifecycle state also keeps completed failures cached, lets an owning task drain cancellation after
release(), validates legacythrow()arguments before creating a bridge, cancels pending WinRT work onclose(), and releases progress callback captures after task completion or cancellation.Progress dispatch is owned by the projected operation. The native WinRT delegate keeps only a weak dispatcher reference, while queued loop callbacks reference a mutable dispatch slot rather than the observer directly. Terminal execution clears that slot under the GIL, making already-queued and later native notifications harmless no-ops; dispatch also checks for a closed loop before scheduling. The cached cancelled future remains intact so a direct await after task cancellation still observes
asyncio.CancelledError.The public compatibility protocols remain structural and unchanged. Generated methods use separate coroutine-capable return protocols, allowing strict mypy to accept their results as both legacy WinRT operations and
Coroutine[Any, Any, T]values without forcing existing adapters to implementsend(),throw(), orclose().Rebase
Rebased the three-commit series onto
54a3912(origin/main), preserving the copiedIBufferconversions from #129 and explicit Pythonunbox_objectAPIs from #131.Rewritten commits:
5661fd3,d0a3b9c,9778588.Validation
TestHttpProgress::test_struct_progress_survives_asyncio_dispatch: 20/20 passed with Rust LLVM coverage instrumentation and Python coverage tracingmypy.stubtest: success, 2 modulescargo fmt --all -- --checkcargo test -p dynwinrt-py --lib: 5 passedcargo test -p dynwinrt-codegen: 564 passed across 30 suites.\tests\e2e\e2e_test.ps1 -SkipBuild -Lang py: strict mypy success; 42 E2E checks passed, 0 failed