This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author asvetlov
Recipients ajoino, alex.gronholm, asvetlov, chris.jerdonek, gvanrossum, iritkatriel, jab, njs, tinchester, yselivanov
Date 2022-02-20.18:45:12
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1645382713.0.0.184911687541.issue46771@roundup.psfhosted.org>
In-reply-to
Content
In docs we can explain the behavior as "the outer expired timeout cancels the inner waiter, waits for CancelError bubbling up, and raising TimeoutError instead".

I agree that a counter is required for this behavior.
An alternative implementation can use the global `dict[Task, int]` for keeping counters. It can be either WeakKeyDictionary or a regular dict that deletes entries on `task.add_done_callback()` call.  We have a similar structure for `asyncio.all_tasks()` support already.

The global dict has a benefit: it doesn't overlap with the user's `.cancel()` calls but counts timeouts only.

A few words regarding task internals: _must_cancel boolean flag is set when a task doesn't wait for something, it was just created or `await sleep(0)` context switch was executed on the previous step.
Otherwise, a task always waits for a future completion, the future is stored as _fut_waiter.

If we use the global counting dict, timeout could call `.cancel()` only if the cancellation was not initiated previously. The current behavior works fine with this as the second `.cancel()` call is ignored.  Technically the ignorance could be reverted, `task.cancelling()` check is enough.

> If we don't set must-cancel, its cleanup is "shielded"

If I understand it correctly, I want this feature. Cleanup can perform async operations for a graceful resources shutdown, cancelling these cleaups look dangerous. With the current asyncio state, you can do it by calling `task.uncancel(); task.cancel()` in a line though.
History
Date User Action Args
2022-02-20 18:45:13asvetlovsetrecipients: + asvetlov, gvanrossum, njs, jab, alex.gronholm, chris.jerdonek, yselivanov, tinchester, iritkatriel, ajoino
2022-02-20 18:45:13asvetlovsetmessageid: <1645382713.0.0.184911687541.issue46771@roundup.psfhosted.org>
2022-02-20 18:45:12asvetlovlinkissue46771 messages
2022-02-20 18:45:12asvetlovcreate