gh-150058: asyncio: preserve Task.cancel() msg through fut_waiter and CancelledError paths#150057
gh-150058: asyncio: preserve Task.cancel() msg through fut_waiter and CancelledError paths#150057prince8273 wants to merge 4 commits into
Conversation
|
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
|
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
2807a14 to
8b1d2b2
Compare
Documentation build overview
4 files changed± library/shutil.html± library/zipfile.html± whatsnew/3.16.html± whatsnew/changelog.html |
|
Please stop updating your branch, it wastes CI resources. Read the devguide to understand our guidelines. |
|
Closing this PR. After testing on the CPython main branch locally, the cancel message is correctly preserved in CancelledError.args. The bug I reported does not reproduce — the fix is not needed. Apologies for the noise. |
When Task.cancel(msg=...) is called while the task is waiting on another
future, the message was silently discarded in two places:
cancel(): the fast path (_fut_waiter.cancel(msg) returns True)
returned immediately without storing msg in _cancel_message.
__step_run_and_handle_result(): the CancelledError handler called
future_cancel(..., NULL), dropping _cancel_message even when set.
Fix both in tasks.py (_PyTask) and _asynciomodule.c (Task).
Also includes:
test_task_cancel_waiter_future_with_message covers the full
round-trip — cancel with msg while awaiting a future, verify the
message reaches the final CancelledError.