Skip to content

Pyjo.Reactor.Trio: run_coroutine returns a function that cancels the task - #17

Draft
dex4er wants to merge 3 commits into
mainfrom
cancel-coroutines
Draft

dex4er wants to merge 3 commits into
mainfrom
cancel-coroutines

Conversation

@dex4er

@dex4er dex4er commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

The reactor of Trio for the cancellation of coroutines of pyjoyment/Pyjoyment#611 (pyjoyment/Pyjoyment#266): an async def action whose connection closes before its response ends is cancelled where it waits, with the request of the user agent that it waits for.

Changes

  • run_coroutine returns a function that cancels the task, with a trio.CancelScope of its own, which takes its own trio.Cancelled and not the one of the end of the run. The scope is cancelled in a task of the run, or at its next tick elsewhere, as between the guest ticks of the own run, as the scopes of the watchers are.
  • awaitable cancels the promise that a task waits for, as promise.cancel(), when the wait is cancelled.
  • pyproject.toml takes Pyjoyment of main with tool.uv.sources, which has Pyjoyment, Pyjo.Promise: async actions and their requests are cancelled when the connection closes Pyjoyment#611 merged, so that CI tests against it; after the release of Pyjoyment it moves to the release, with dependencies raised to it. Until then this pull request stays a draft.

Validation

  • t/Reactor_Trio.py: the cancellation in a run of Trio and in the own run of the reactor, with the promise that the coroutine waits for
  • The suite of Pyjoyment of the branch on this reactor, with t/Pyjoyment/cancel_lite_app.py, which it skipped before, with PYTHONDEVMODE=1, without a ResourceWarning
  • trunk check, with pyright of Pyjoyment of the branch

🤖 Generated with Claude Code

dex4er and others added 2 commits November 12, 2026 16:27
…task, with a cancel scope of its own

The coroutine gets trio.Cancelled where it waits, and the promise that it
waits for is cancelled, so that Pyjoyment cancels an async action whose
connection closes before its response ends, with the request of the user
agent that it waits for. The scope is cancelled in a task of the run, or at
its next tick elsewhere, as between the guest ticks of the own run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…l its release

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@read-the-docs-community

read-the-docs-community Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

Documentation build overview

📚 Pyjo-Reactor-Trio | 🛠️ Build #35844832 | 📁 Comparing fcc97ba against latest (1123c01)

  🔍 Preview build  

1 file changed
± index.html

@github-actions

Copy link
Copy Markdown
Contributor

Tests

Job Tests Passed ✅ Skipped ⚠️ Failed ❌ Log
prove (python 3.12) 7345 7312 33 0 ✅ 131286140009
prove (python 3.13) 7345 7312 33 0 ✅ 131286139917
prove (python 3.14) 7376 7348 28 0 ✅ 131286140020
prove (python 3.15) 7376 7348 28 0 ✅ 131286140668
prove (python 3.15t) 7376 7348 28 0 ✅ 131286140289
prove (python pypy3.12) 7345 7312 33 0 ✅ 131286140286
All 44163 43980 183 0 ✅

The run of the workflow

…ease

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown
Contributor

Tests

Job Tests Passed ✅ Skipped ⚠️ Failed ❌ Log
prove (python 3.12) 7360 7327 33 0 ✅ 131330860584
prove (python 3.13) 7360 7327 33 0 ✅ 131330860574
prove (python 3.14) 7391 7363 28 0 ✅ 131330860601
prove (python 3.15) 7391 7363 28 0 ✅ 131330861293
prove (python 3.15t) 7391 7363 28 0 ✅ 131330860772
prove (python pypy3.12) 7360 7327 33 0 ✅ 131330860650
All 44253 44070 183 0 ✅

The run of the workflow

This branch has not been deployed

No deployments
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