[issue46771] Add some form of cancel scopes

Alex Grönholm report at bugs.python.org
Sun Feb 20 16:46:35 EST 2022


Alex Grönholm <alex.gronholm at nextday.fi> added the comment:

> It looks more complicated -- the extra parameter needs to be passed around via the task and then into the CancelledError exception.

It reduces overall complexity by making uncancellation unnecessary and restoring backwards compatibility.

> What use case do you have that cannot be solved by some variation of the "cancel count" proposal?

I'm not sure I'm keeping proper track of the variations, but it seems it still relies on task uncancellation. But worse than that, (correct me if I'm wrong) it makes the innermost context manager handle the cancellation, even if it was requested by an outer one. If you have 3 nested "cancel scopes" and the task is cancelled once, how do you know which one of those context managers should handle the cancellation?

I'm not sure my proposal is a fix-all either, in its current form. Sure, it fixes the case where a full task cancellation would go unnoticed, but if two unrelated context managers trigger cancellation at the same time, only the first one would actually receive it. Perhaps then we need to raise a CancelledError separately for each scope? I'm not sure yet.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue46771>
_______________________________________


More information about the Python-bugs-list mailing list