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 methane
Recipients abacabadabacaba, methane, yselivanov
Date 2017-04-13.00:19:12
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1492042753.82.0.420596114718.issue30048@psf.upfronthosting.co.za>
In-reply-to
Content
> The problem is that the task doesn't catch CancelledError, yet it disappears.

The problem is CancelledError is not raised, even it's thrown.
Task can't catch exception not raised.  See below example which demonstrates how task works.

---
from asyncio import CancelledError

cancelled = False

def coro():
    global cancelled
    print(1)
    yield (1,)
    print("cancel")
    cancelled = True
    #print(2)
    #yield (2,)  # uncomment this line makes cancel success.

c = coro()

while True:
    try:
        if cancelled:
            r = c.throw(CancelledError)
        else:
            r = c.send(None)
    except StopIteration:
        print("end")
        break
    except CancelledError:
        print("cancelled")
        break
History
Date User Action Args
2017-04-13 00:19:13methanesetrecipients: + methane, abacabadabacaba, yselivanov
2017-04-13 00:19:13methanesetmessageid: <1492042753.82.0.420596114718.issue30048@psf.upfronthosting.co.za>
2017-04-13 00:19:13methanelinkissue30048 messages
2017-04-13 00:19:12methanecreate