Skip to content

TaskGroup propagates CancelledError rather than a MultiError on exception #34

Closed

Description

@bdowning

See the following snippet:

import asyncio
import aiotools

async def error():
    await asyncio.sleep(1)
    raise Exception("bad stuff")

async def main():
    try:
        async with aiotools.TaskGroup() as tg:
            tg.create_task(error())
            await asyncio.sleep(5)
    except Exception as e:
        print(f"Got inner {repr(e)}")
        raise

try:
    asyncio.run(main())
except BaseException as e:
    print(f"Got outer {repr(e)}")
Got outer CancelledError()

Is this expected behavior? It feels wrong, since a) it ate an exception and b) the task wasn't actually cancelled.

This is Python 3.9 and aiotools 1.4.0.

Activity

  1. achimnol commented on Feb 21, 2022

    @achimnol
    Owner

    Let's inspect how python/cpython#31270 handles this...

  2. achimnol commented on Feb 21, 2022

    @achimnol
    Owner
  3. achimnol commented on Feb 27, 2022

    @achimnol
    Owner

    I have tested your code with asyncio.TaskGroup introduced in Python 3.11 development version.

    Got inner ExceptionGroup('unhandled errors in a TaskGroup', [Exception('bad stuff')])
    Got outer ExceptionGroup('unhandled errors in a TaskGroup', [Exception('bad stuff')])
    

    With aiotools.TaskGroup,

    Got outer CancelledError()
    

    It seems to have some problem, definitely. I'll look into more.

  4. added a commit that references this issue on Feb 28, 2022
    0051cd9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions