Guido van Rossum <[email protected]> added the comment:
> If some code is used together with timeout() and this code calls
> `.cancel()` but forgot about `.uncancel()` in try/except/finally --
> timeout() never raises TimeoutError.
Could you show an example? I'm not sure from this description who cancels whom
and where the try/except/finally is in relation to the rest.
If you have something that catches CancelledError and then ignores it, e.g.
while True:
try:
await <something>
except CancelledError:
pass
then that's an immortal task and it shouldn't be run inside a timeout.
If you have something that catches CancelledError once, e.g.
try:
await <big action>
finally:
await <cleanup>
there should be no need to call .uncancel() *unless* the <cleanup> may hang --
in that case you could write
try:
await <big action>
finally:
async with timeout(5):
await <cleanup>
I'm not sure that we should recommend using .uncancel() except in very special
cases (e.g. when writing a timeout() context manager :-) and those cases should
just be tested.
----------
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue46771>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com