8000 extmod uasyncio: Cancelling a gather only cancels one task instead of all · Issue #5798 · micropython/micropython · GitHub
[go: up one dir, main page]

Skip to content
extmod uasyncio: Cancelling a gather only cancels one task instead of all #5798
Closed
@kevinkk525

Description

@kevinkk525

This is easy to explain, cancelling a gather(...) will only cancel one task, the remaining ones still continue.

Testcase:

async def test_gather_cancel_itself():
    res = []

    async def consumer():
        nonlocal res
        try:
            await asyncio.sleep(1)
        except asyncio.CancelledError:
            dprint("wait() cancelled")
            res.append(True)
        else:
            res.append(False)

    async def gather():
        t = []
        for _ in range(5):
            t.append(asyncio.create_task(consumer()))
        try:
            await asyncio.gather(*t)
        except asyncio.CancelledError:
            print("gather cancelled")

    t = asyncio.create_task(gather())
    await asyncio.sleep(0.1)
    t.cancel()
    await asyncio.sleep(1.5)
    return res

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0