]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
bpo-34872: Fix self-cancellation in C implementation of asyncio.Task 9679/head
authorElvis Pranskevichus <elvis@magic.io>
Tue, 2 Oct 2018 23:10:32 +0000 (19:10 -0400)
committerElvis Pranskevichus <elvis@magic.io>
Tue, 2 Oct 2018 23:36:41 +0000 (19:36 -0400)
commit548ce9dedd2e90945970671d441436a6a91608ab
treef2c2ae7d5c9b757c6c2e3af3bdec5dca21a0f933
parent97bfe8d3ebb0a54c8798f57555cb4152f9b2e1d0
bpo-34872: Fix self-cancellation in C implementation of asyncio.Task

The C implementation of asyncio.Task currently fails to perform the
cancellation cleanup correctly in the following scenario.

    async def task1():
        async def task2():
            await task3     # task3 is never cancelled

        asyncio.current_task().cancel()
        await asyncio.create_task(task2())

The actuall error is a hardcoded call to `future_cancel()` instead of
calling the `cancel()` method of a future-like object.

Thanks to Vladimir Matveev for noticing the code discrepancy and to
Yury Selivanov for coming up with a pathological scenario.
Lib/test/test_asyncio/test_tasks.py
Misc/NEWS.d/next/Library/2018-10-02-19-36-34.bpo-34872.yWZRhI.rst [new file with mode: 0644]
Modules/_asynciomodule.c