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 gvanrossum
Recipients ajoino, alex.gronholm, asvetlov, chris.jerdonek, dreamsorcerer, gvanrossum, iritkatriel, jab, njs, tinchester, yselivanov
Date 2022-02-21.03:46:12
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1645415172.66.0.320356756751.issue46771@roundup.psfhosted.org>
In-reply-to
Content
[Sam]
> It will probably work in this case. But, what about more complex cases? If there are 2 different timeouts and the possibility of a user cancellation, and we have a count of 2 cancellations, then what happened? 2 timeouts, or 1 timeout and user cancellation? Without being able to check the nonces of each cancellation, I don't see how this would work. Or if the user calls .cancel() twice explicitly, then you cancel both timeouts, even though it had nothing to do with the timeout.

The cancel scope must record whether it called cancel() or not. (This is what TaskGroup does.) Suppose the inner timeout cancels and sees two cancellations. It knows one of those is its own, so it calls uncancel() and raises CancelledError. Now the outer cancel scope sees one cancellation. If it did not call cancel(), it knows it was a user cancellation (or another, even more outer, cancel scope -- it really doesn't matter), and it raises CancelledError. If the outer cancel scope also called cancel(), it knows that this is so, and it in turn calls uncancel() -- and it knows (by the count returned from uncancel()) that there are no more cancellations, so it raises TimeoutError.

QED
History
Date User Action Args
2022-02-21 03:46:13gvanrossumsetrecipients: + gvanrossum, njs, jab, asvetlov, alex.gronholm, chris.jerdonek, yselivanov, tinchester, iritkatriel, dreamsorcerer, ajoino
2022-02-21 03:46:12gvanrossumsetmessageid: <1645415172.66.0.320356756751.issue46771@roundup.psfhosted.org>
2022-02-21 03:46:12gvanrossumlinkissue46771 messages
2022-02-21 03:46:12gvanrossumcreate