Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

The asyncio REPL interactive daemon thread doesn't handlePYTHONSTARTUP exceptions #140287

Open
Labels
3.13bugs and security fixes3.14bugs and security fixes3.15new features, bugs and security fixesstdlibStandard Library Python modules in the Lib/ directorytopic-asynciotopic-replRelated to the interactive shelltype-bugAn unexpected behavior, bug, or error
@johnslavik

Description

@johnslavik

Bug report

Bug description:

That leads to flaky behaviors.

This is myPYTHONSTARTUP file:

raiseModuleNotFoundError("oops!")

ModuleNotFoundError is just an example exception that can occur inPYTHONSTARTUP scripts.

This is how the regular REPLs handle it (both the basic REPL and the new REPL):

❯ PYTHONSTARTUP=t.py ./pythonPython 3.15.0a1+ (heads/main:fbf0843e39e, Oct 18 2025, 11:24:43) [GCC 15.2.1 20250808 (Red Hat 15.2.1-1)] on linuxType "help", "copyright", "credits" or "license" for more information.Traceback (most recent call last):  File "t.py", line 1, in <module>    raise ModuleNotFoundError("oops!")ModuleNotFoundError: oops!>>>

The traceback is shown and we proceed to the loop.

For the asyncio REPL, startup file exception always causes it to exit immediately -- we'd never want the REPL to exit because of a startup file error. On top of that, it doesn't report the exception properly, because it's racing with the interpreter shutdown at that point.

I've found 3 variants of the incorrect behavior:

  1. The interactive daemon thread doesn't write the full traceback:

    ❯ PYTHONSTARTUP=t.py ./python -m asyncioasyncio REPL 3.15.0a1+ (heads/main:fbf0843e39e, Oct 18 2025, 11:24:43) [GCC 15.2.1 20250808 (Red Hat 15.2.1-1)] on linuxUse "await" directly instead of "asyncio.run()".Type "help", "copyright", "credits" or "license" for more information.Exception in thread Interactive thread:exiting asyncio REPL...Traceback (most recent call last):
  2. The interactive daemon thread does flush, but after exiting is reported:

    ❯ PYTHONSTARTUP=t.py ./python -m asyncioasyncio REPL 3.15.0a1+ (heads/main:fbf0843e39e, Oct 18 2025, 11:24:43) [GCC 15.2.1 20250808 (Red Hat 15.2.1-1)] on linuxUse "await" directly instead of "asyncio.run()".Type "help", "copyright", "credits" or "license" for more information.Exception in thread Interactive thread:exiting asyncio REPL...Traceback (most recent call last):  File "/home/bswck/Python/cpython/Lib/threading.py", line 1075, in _bootstrap_inner    self._context.run(self.run)    ~~~~~~~~~~~~~~~~~^^^^^^^^^^  File "/home/bswck/Python/cpython/Lib/asyncio/__main__.py", line 104, in run    exec(startup_code, console.locals)    ~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  File "t.py", line 1, in <module>    raise ModuleNotFoundError("oops!")ModuleNotFoundError: oops!
  3. The interactive daemon tries to acquire stderr at interpreter shutdown, and fails:

    ❯ PYTHONSTARTUP=t.py ./python -m asyncioasyncio REPL 3.15.0a1+ (heads/main:fbf0843e39e, Oct 18 2025, 11:24:43) [GCC 15.2.1 20250808 (Red Hat 15.2.1-1)] on linuxUse "await" directly instead of "asyncio.run()".Type "help", "copyright", "credits" or "license" for more information.Exception in thread Interactive thread:exiting asyncio REPL...Traceback (most recent call last):  File "/home/bswck/Python/cpython/Lib/threading.py", line 1075, in _bootstrap_inner    self._context.run(self.run)    ~~~~~~~~~~~~~~~~~^^^^^^^^^^Fatal Python error: _enter_buffered_busy: could not acquire lock for <_io.BufferedWriter name='<stderr>'> at interpreter shutdown, possibly due to daemon threadsPython runtime state: finalizing (tstate=0x00000000009c3818)Current thread 0x00007f6c4781cbc0 [python] (most recent call first):  <no Python frame>Aborted (core dumped)

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.13bugs and security fixes3.14bugs and security fixes3.15new features, bugs and security fixesstdlibStandard Library Python modules in the Lib/ directorytopic-asynciotopic-replRelated to the interactive shelltype-bugAn unexpected behavior, bug, or error

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp