Skip to content

TaskGroup reports a child task's SystemExit as not propagated #162492

Open

Description

@fedonman

Bug description:

When a child task of an asyncio.TaskGroup raises SystemExit or KeyboardInterrupt, the task group propagates that exception and also passes it to the event loop's exception handler as an exception that was "not propagated".

import asyncio

async def child():
    raise SystemExit(3)

async def main():
    loop = asyncio.get_running_loop()
    loop.set_exception_handler(lambda loop, ctx: print(ctx['message'], repr(ctx['exception'])))
    async with asyncio.TaskGroup() as tg:
        tg.create_task(child())
        await asyncio.sleep(1)

asyncio.run(main())

Output on main (the process exits with status 3):

TaskGroup task exception was not propagated because the TaskGroup body is being closed with a BaseException SystemExit(3)
Task exception was never retrieved SystemExit(3)

The first line comes from the reporting added for gh-135736 and is new in 3.16; 3.15 prints only the second line. With the default exception handler it is logged as an error with the full traceback of the SystemExit.

Expected: the exception that propagates out of the task group is not reported. Errors from other tasks are still reported.

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs

Activity

  1. added
    stdlib
    type-bug
    on Nov 23, 2026
  2. gvanrossum commented on Nov 23, 2026

    @gvanrossum
    Member

    This is intentional. Those exceptions ought to only be raised in order to stop the entire thread (remember one loop per thread).

    If you are calling something that somehow raises one of these, you ought to catch those at the calling site.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibtopic-asynciotype-bug

    Projects

    • Status
      Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions