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-23.02:52:33
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1645584753.27.0.706374088427.issue46771@roundup.psfhosted.org>
In-reply-to
Content
> 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.
History
Date User Action Args
2022-02-23 02:52:33gvanrossumsetrecipients: + gvanrossum, njs, jab, asvetlov, alex.gronholm, chris.jerdonek, yselivanov, tinchester, iritkatriel, dreamsorcerer, ajoino
2022-02-23 02:52:33gvanrossumsetmessageid: <1645584753.27.0.706374088427.issue46771@roundup.psfhosted.org>
2022-02-23 02:52:33gvanrossumlinkissue46771 messages
2022-02-23 02:52:33gvanrossumcreate