Skip to content

asyncio blocks custom BaseException exceptions #108711

Closed as not planned
Closed as not planned
@CendioOssman

Description

@CendioOssman

Bug report

Checklist

  • I am confident this is a bug in CPython, not a bug in a third-party project
  • I have searched the CPython issue tracker,
    and am confident this bug has not been reported before

CPython versions tested on:

3.11

Operating systems tested on:

Linux

Output from running 'python -VV' on the command line:

Python 3.11.4 (main, Jun 7 2023, 00:00:00) [GCC 13.1.1 20230511 (Red Hat 13.1.1-2)]

A clear and concise description of the bug:

Since bpo-32528, this code no longer works:

import asyncio

class ShowStopper(BaseException):
    pass

def hello_world(loop):
    print('Hello World')
    raise ShowStopper("Stop")

loop = asyncio.get_event_loop()

loop.call_soon(hello_world, loop)

loop.run_forever()
loop.close()

I think this behaviour is very surprising as the general behaviour of exceptions based on BaseException is that they propagate over error handling. Currently, we'd need to do something hacky like inherit from SystemExit instead, basically relegating BaseException to something internal.

This issue was mentioned in the PR, and supposed to be adjusted for Python 3.9:

#13528 (review)

Unfortunately, it seems that was forgotten.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions