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 <>
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()
    async def job():
        if random.random() < 0.5:
            await asyncio.sleep(2)
        await asyncio.sleep(5)
    task = asyncio.create_task(job())
    await asyncio.sleep(1)
    task.cancel("cancel task")
    await task

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.
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: <>
2022-02-23 17:27:45serhiy.storchakalinkissue45390 messages
2022-02-23 17:27:45serhiy.storchakacreate