Skip to content

Fix Python lifetime scope thread affinity - #134

Merged
leileizhang (lei9444) merged 3 commits into
mainfrom
lei9444-python-lifetime-affinity
Sep 4, 2026
Merged

leileizhang (lei9444) merged 3 commits into
mainfrom
lei9444-python-lifetime-affinity

Conversation

@lei9444

@lei9444 leileizhang (lei9444) commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • make ProjectedLifetimeScope capture its owner thread and reject foreign-thread enter, tracking, and close operations before registry mutation or native release
  • centralize callback ContextVar replay so same-thread callbacks retain the captured active scope, while foreign-thread callbacks mask only that inherited lifetime scope
  • apply the callback contract to generated delegates, raw DynWinRTValue.on_progress() handlers, and agile DynWinRtElementFactory get/recycle callbacks; preserve original callbacks as unraisable error targets and keep element return cast ownership unchanged
  • preserve callback ownership semantics: retained foreign-callback wrappers remain live and explicitly releasable, while ordinary unretained temporaries still drop on the callback thread
  • cover asyncio.to_thread, copied contexts, manual foreign-thread operations, retained/unretained delegate values, real native HTTP progress, and foreign-thread element-factory get/recycle behavior
  • keep the runtime support statement in the root README while describing the standalone codegen wheel without prominently advertising Python 3.8; document callback and worker-thread lifetime rules

Validation

  • cargo fmt --all and cargo fmt --all -- --check
  • cargo test -p dynwinrt-py --quiet — 5 passed
  • cargo test -p dynwinrt-codegen --quiet — full suite passed
  • python -m maturin build --release and wheel reinstall — CPython 3.13 ARM64 wheel built
  • python -m pytest bindings\py\tests -q — 151 passed, including real HTTP progress and direct agile element-factory cross-thread regressions
  • python -m mypy.stubtest dynwinrt --allowlist bindings\py\stubtest_allowlist.txt --ignore-disjoint-bases — passed
  • .\tests\e2e\e2e_test.ps1 -SkipBuild -Lang py — strict mypy passed; Python WinRT E2E 42/42 passed
  • live ARM64 WinUI E2E was attempted with the CI-pinned WinAppSDK package versions, but its generated UIElement module lacks IID_IUIElement; the existing runner reports that callback exception through sys.unraisablehook while returning exit code 0, before element-factory coverage begins

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@github-actions

github-actions Bot commented Sep 4, 2026 •

Copy link
Copy Markdown

Mixed-language test coverage

Workflow status: ✅ Passed

Layer Lines Functions Branches/regions
Rust, including native .pyd/.node 84.99% 80% 84.54% regions
Generated Python projections 70.48% n/a 21.71% branches
JavaScript aggregate 21.46% 20.64% 54.23% branches
JavaScript runtime 24.22% 14.28% 7.14% branches
Generated WinRT projections 25.8% 19.3% 54.74% branches
Generated Classic COM projections 14.83% 24.65% 54.38% branches

View workflow run and download full HTML/LCOV/XML reports

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 778823b5-9f70-4a61-95a9-19e3d37f95e9
@lei9444
leileizhang (lei9444) merged commit b48f1c7 into main Sep 4, 2026
24 checks passed
@lei9444
leileizhang (lei9444) deleted the lei9444-python-lifetime-affinity branch September 4, 2026 08:59
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