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 serhiy.storchaka
Recipients asvetlov, bjs, chris.jerdonek, graingert, gvanrossum, pagliaricci.m, serhiy.storchaka, yselivanov
Date 2022-02-23.17:27:45
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1645637265.64.0.953578636346.issue45390@roundup.psfhosted.org>
In-reply-to
Content
Also Future.result() and Future.exception() can raise a CancelledError. So a CancelledError raised in a task may not contain a message passed to Task.cancel().

import asyncio
import random

async def main():
    fut = asyncio.Future()
    fut.cancel()
    async def job():
        if random.random() < 0.5:
            await asyncio.sleep(2)
        fut.result()
        await asyncio.sleep(5)
    task = asyncio.create_task(job())
    await asyncio.sleep(1)
    task.cancel("cancel task")
    await task

asyncio.run(main())

You need to catch a CancelledError raised in a coroutine and re-raise a new CancelledError with the specified cancel message if the task was cancelled.
History
Date User Action Args
2022-02-23 17:27:45serhiy.storchakasetrecipients: + serhiy.storchaka, gvanrossum, asvetlov, chris.jerdonek, yselivanov, graingert, bjs, pagliaricci.m
2022-02-23 17:27:45serhiy.storchakasetmessageid: <1645637265.64.0.953578636346.issue45390@roundup.psfhosted.org>
2022-02-23 17:27:45serhiy.storchakalinkissue45390 messages
2022-02-23 17:27:45serhiy.storchakacreate