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 alex.gronholm
Recipients ajoino, alex.gronholm, asvetlov, chris.jerdonek, gvanrossum, iritkatriel, jab, njs, tinchester, yselivanov
Date 2022-02-18.13:12:51
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1645189971.2.0.0142095896053.issue46771@roundup.psfhosted.org>
In-reply-to
Content
I propose the following, backwards compatible solution:

Add a new keyword argument to Task.cancel(): "scope: object = None".
The behavior would be as follows: the scope is saved, and included in the raised CancelledError. If Task.cancel() is called again, but with scope=None (the default), it clears out the saved scope, if any. Any other scope will be ignored.

This simple change would allow for proper implementation of any context manager that needs to swallow or transform a CancelledError raised in the task.
History
Date User Action Args
2022-02-18 13:12:51alex.gronholmsetrecipients: + alex.gronholm, gvanrossum, njs, jab, asvetlov, chris.jerdonek, yselivanov, tinchester, iritkatriel, ajoino
2022-02-18 13:12:51alex.gronholmsetmessageid: <1645189971.2.0.0142095896053.issue46771@roundup.psfhosted.org>
2022-02-18 13:12:51alex.gronholmlinkissue46771 messages
2022-02-18 13:12:51alex.gronholmcreate