Serhiy Storchaka <[email protected]> added the comment:
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.
----------
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue45390>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com