Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-141186: Document asyncio Task cancellation propagation behavior#141247

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation

@mohsinm-dev
Copy link

@mohsinm-devmohsinm-dev commentedNov 8, 2025
edited by github-actionsbot
Loading

Fixes issue#141186 by documenting that cancelling a Task cancels what it's waiting for.

Problem

The docs said cancelling a coroutine waiting on a Future cancels the Future, but didn't mention this also happens with Tasks. Users didn't know Tasks work the same way.

Solution

  • Added "or Task" to the documentation where it only mentioned Future
  • Explained that cancellation goes down the whole chain of waiting tasks
  • Mentioned that Tasks inherit from Future so they work the same

Testing

Ran the exact code from the issue - it works as expected. Tested multiple scenarios to confirm the behavior.

Documentation-only change. No code was modified.


📚 Documentation preview 📚:https://cpython-previews--141247.org.readthedocs.build/

Changed "Objects of different types, except different numeric types, nevercompare equal" to "Objects of different types, unless documented otherwise,never compare equal" to account for documented exceptions like set/frozensetcomparisons.
The acquire() method documentation stated 'Exactly one thread will be awokenby each call to release()' which became incorrect when the n parameter wasadded to release() in Python 3.9.The release() method documentation was ambiguous about behavior whenn > waiting_threads.Changes:- acquire(): Updated to reflect that release(n) wakes min(j,n) threads  where j = waiting threads- release(): Clarified that it wakes 'up to n' threads, or all available  if fewer than n are waitingThe fix aligns documentation with actual implementation behavior inLib/threading.py where release(n) calls Condition.notify(n).
Clarifies that cancelling a Task awaiting another Task or Future willalso cancel the awaited object. This behavior was undocumented despitebeing fundamental to asyncio's cancellation architecture.Changes:- Updated general Task description to mention Task cancellation propagation- Added explicit explanation in Task.cancel() method documentation- Clarified that Tasks inherit Future's cancellation behaviorAddresses issuepython#141186 where users were unaware this cancellationpropagation was intentional architectural behavior, not a side effect.The fix uses the exact wording suggested by the issue reporter anddocuments the _fut_waiter implementation behavior that enables thepropagation down entire await chains.
Copy link
Member

@StanFromIrelandStanFromIreland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

You seem to have changes for three different issues in this PR, please remove the unrelated ones.

@mohsinm-dev
Copy link
Author

Closing this PR due to mixed commits from multiple issues. Will create a clean PR with only the asyncio changes.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@StanFromIrelandStanFromIrelandStanFromIreland left review comments

@1st11st1Awaiting requested review from 1st11st1 is a code owner

@asvetlovasvetlovAwaiting requested review from asvetlovasvetlov is a code owner

@kumaraditya303kumaraditya303Awaiting requested review from kumaraditya303kumaraditya303 is a code owner

@willingcwillingcAwaiting requested review from willingcwillingc is a code owner

Assignees

No one assigned

Labels

docsDocumentation in the Doc dirskip news

Projects

Status: Todo

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

@mohsinm-dev@StanFromIreland

[8]ページ先頭

©2009-2025 Movatter.jp