Repository navigation
The asyncio REPL interactive daemon thread doesn't handle PYTHONSTARTUP exceptions #140287
Copy link
Copy link
Closed
Closed
Copy link
Labels
3.13only security fixesonly security fixes3.14bugs and security fixesbugs and security fixes3.15bugs and security fixesbugs and security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-asynciotopic-replRelated to the interactive shellRelated to the interactive shelltype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Activity
- addedtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
on Oct 18, 2025 CC @ZeroIntensity (mentorship) I'd add these labels:
stdlib,type-repl,type-asyncio. Perhaps also version labels once I reproduce for all versions.Reacted by Peter BiermaThe simplest fix is to just handle these exceptions with
sys.excepthook(viaconsole.showtraceback).Interestingly,
_pyrepldoesn't seem to properly handle this as well whenpythonstartup=Trueis passed to_pyrepl.main.interactive_console.PYTHONSTARTUP=t.py ./python -c 'import _pyrepl.main; _pyrepl.main.interactive_console(pythonstartup=True)'exits immediately. However, it doesn't suffer from problems that daemonic threads do. I need to check that later.Reacted by msmojtabafar- addedstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-replRelated to the interactive shellRelated to the interactive shell
on Oct 18, 2025 This is a bugfix -- let's add 3.13, 3.14 and 3.15 here cc @ZeroIntensity mentorship
Reacted by Peter Bierma- added3.13only security fixesonly security fixes3.14bugs and security fixesbugs and security fixes3.15bugs and security fixesbugs and security fixes
on Nov 8, 2025 - added a commit that references this issue
on Apr 25, 2026
Metadata
Metadata
Assignees
Labels
3.13only security fixesonly security fixes3.14bugs and security fixesbugs and security fixes3.15bugs and security fixesbugs and security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-asynciotopic-replRelated to the interactive shellRelated to the interactive shelltype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Projects
- StatusShow more project fieldsDone
Bug report
Bug description:
That leads to flaky behaviors.
This is my
PYTHONSTARTUPfile:ModuleNotFoundErroris just an example exception that can occur inPYTHONSTARTUPscripts.This is how the regular REPLs handle it (both the basic REPL and the new REPL):
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:
The interactive daemon thread doesn't write the full traceback:
The interactive daemon thread does flush, but after exiting is reported:
The interactive daemon tries to acquire stderr at interpreter shutdown, and fails:
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux
Linked PRs
PYTHONSTARTUPscript exceptions in the asyncio REPL #140288PYTHONSTARTUPscript exceptions in the asyncio REPL (GH-140288) #148987PYTHONSTARTUPscript exceptions in the asyncio REPL (GH-140288) #148988