[issue46771] Add some form of cancel scopes

Andrew Svetlov report at bugs.python.org
Fri Feb 18 06:52:09 EST 2022


Andrew Svetlov <andrew.svetlov at gmail.com> added the comment:

Guido, the third case:

The third edge case is: explicit cancel() happened *after* the timeout (but still in the
same iteration)?

   timeout  current-iteration (calls .cancel() after timeout)  next-iteration
     |                            |                                 |
 >---+----------------------------+---------------------------------+----------> future

  a) timeout occurs, `call_later()`' callback is called, the task cancellation is scheduled 
  on the next loop iteration by `task.cancel()` call
  b) other activity (e.g. socket-ready event that processed after timers in asyncio)
  explicitly calls `.cancel()`. The second request is ignored, `.cancel()` returns `False`.
  c) On the next iteration, the task wakes up with CancelledError with a message that points
  on the timeout context manager. 

It means that the timeout is processed, explicit `.cancel()` call that happens *after*
timeout is ignored. The first event wins, as usual.

----------

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


More information about the Python-bugs-list mailing list