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
History and Details
python/cpython PR 112950, released in Python 3.13, added the from rlcompleter import Completer to Lib/pdb.py. There was no top-level indirect import of readline before this.
- This only impacts
import readline when it's backed by GNU libreadline. Notably, the Mac default Python installation uses libedit instead, so on Macs this can only be reproduced by using conda or pyenv with a separately downloaded copy of Python 3.13.
Rationale
- Any code that directly or indirectly imports
pdb ends up importing readline, potentially causing a deadlock, even if the caller never actually intends to use pdb.
- Notably, all direct cases of
import readline in Lib/pdb.py are already lazy, so this is a an established pattern that was broken by the top-level rlcompleter 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
Bug report
Bug description:
Problem summary
Starting in Python 3.13,
Lib/pdb.pycontains a top-levelfrom rlcompleter import Completer, which indirectly causes a top-levelimport readline, which deadlocks waiting to accessstdinifpdbis imported directly or indirectly in a subprocess launched with eitherprocess_group=0orpreexec_fn=setpgrp.Proposed change
from rlcompleter import CompleterfromLib/pdb.py.from rlcompleter import Completerto the beginnings ofcompletedefaultand_enable_rl_completeHistory and Details
python/cpythonPR 112950, released in Python 3.13, added thefrom rlcompleter import CompletertoLib/pdb.py. There was no top-level indirect import ofreadlinebefore this.import readlinewhen it's backed by GNUlibreadline. Notably, the Mac default Python installation useslibeditinstead, so on Macs this can only be reproduced by usingcondaorpyenvwith a separately downloaded copy of Python 3.13.Rationale
pdbends up importingreadline, potentially causing a deadlock, even if the caller never actually intends to usepdb.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#159645import readlineinLib/pdb.pyare already lazy, so this is a an established pattern that was broken by the top-levelrlcompleterimport.Full writeup
This issue focuses on the
pdbpart 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