-
-
Notifications
You must be signed in to change notification settings - Fork 33k
Open
Labels
3.13bugs and security fixesbugs and security fixes3.14bugs and security fixesbugs and security fixes3.15new features, bugs and security fixesnew features, bugs and security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Bug report
Bug description:
Problem summary
Starting in Python 3.13, Lib/pdb.py
contains a top-level from rlcompleter import Completer
, which indirectly causes a top-level import readline
, which deadlocks waiting to access stdin
if pdb
is imported directly or indirectly in a subprocess launched with either process_group=0
or preexec_fn=setpgrp
.
Proposed change
- Remove top-level
from rlcompleter import Completer
fromLib/pdb.py
. - Lazy import it by adding
from rlcompleter import Completer
to the beginnings ofcompletedefault
and_enable_rl_complete
History and Details
python/cpython
PR 112950, released in Python 3.13, added thefrom rlcompleter import Completer
toLib/pdb.py
. There was no top-level indirect import ofreadline
before this.- This only impacts
import readline
when it's backed by GNUlibreadline
. Notably, the Mac default Python installation useslibedit
instead, so on Macs this can only be reproduced by usingconda
orpyenv
with a separately downloaded copy of Python 3.13.
Rationale
- Any code that directly or indirectly imports
pdb
ends up importingreadline
, potentially causing a deadlock, even if the caller never actually intends to usepdb
.- Specifically, pytorch (
import torch
) imports pdb, and this caused import torch hangs when running in subprocess with preexec_fn=os.setpgrp, python >=3.13, conda env pytorch/pytorch#159645
- Specifically, pytorch (
- Notably, all direct cases of
import readline
inLib/pdb.py
are already lazy, so this is a an established pattern that was broken by the top-levelrlcompleter
import.
Full writeup
This issue focuses on the pdb
part of the problem.
Here's a comprehensive cross-functional writeup about the issue: https://github.com/kelu-wandb/public-demo/tree/main/pgrp-torch-pdb-readline
CPython versions tested on:
3.13
Operating systems tested on:
macOS
Linked PRs
Metadata
Metadata
Assignees
Labels
3.13bugs and security fixesbugs and security fixes3.14bugs and security fixesbugs and security fixes3.15new features, bugs and security fixesnew features, bugs and security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error