You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Pdb loops endlessly on non-interactive scripts #100141
Pdb (as of 3.11.0, 3.11.1 and main branch, run from the command line) loops endlessly on non-interactive scripts.
To reproduce, run python -m pdb /dev/null from the command line. This loops, endlessly printing The program finished and will be restarted to the terminal. Pressing Ctrl + C drops you into the debugger shell, but entering quit only drops you back into that endless loop, I had to kill the process directly to make it quit.
With Python 3.10, it looks like this:
nils@makake:~> python3.10 -m pdb /dev/null
> /dev/null(1)<module>()
(Pdb) quit
nils@makake:~> python3.10 -m pdb -c c /dev/null
The program finished and will be restarted
> /dev/null(1)<module>()
(Pdb) q
nils@makake:~>
Your environment
CPython versions tested on: 3.11.0, 3.11.1, built from current main branch
Operating system and architecture: Fedora Linux 37, x86_64
Pressing Ctrl + C drops you into the debugger shell, but entering quit only drops you back into that endless loop, I had to kill the process directly to make it quit.
I believe this happens because the keyboard interrupt puts you in post-mortem debugging mode, so the subsequent quit command does not apply to the original instance of Pdb, which continues its loop.
This infinite loop also happens with an empty file or one containing no statements (but not "noninteractive scripts" that contain at least one statement), so the trace function that powers the debugger never fires. I'm not sure why/how the older versions started with a prompt even when no statements are present, though.
I've had a closer look at this, the change in behavior between 3.10 and 3.11 appears to be caused by #94552, although I don't really understand which part of pdb.py that's interacting with or how to resolve it.
I found the Bug and wrote a PR, core dev feedback needed
Do we know where this Bug is?
Do we all know the test of: python3 -m pdb /dev/null
still does hang some Python's today?
Exact same cause as before, or a new escape, while none of us add this test?
Three examples =>
1 ) macOS latest fails this test
% </dev/null python3 -m pdb /dev/null 2>&1 |head -3
The program finished and will be restarted
The program finished and will be restarted
The program finished and will be restarted
%
% python3 --version
Python 3.12.6
% uname
Darwin
%
Calling -m pdb to check Python Syntax hangs in this same way on a File of nothing but Comments and Line Breaks
% cat p.py
#
% </dev/null python3 -m pdb p.py 2>&1 |head -3
The program finished and will be restarted
The program finished and will be restarted
The program finished and will be restarted
%
But go wander into the right corner of the Python world, and this problem does not repro out there. For example
Leaving this corner untested made it worse eventually
Python 3.13 came out in Oct/2024, so I reran our tests there. I've now reported the process exit return code gone wrong on Syntax Error's, but also mentioned our infinite spam observations here, up now into
"python3.13 -m pdb" exits zero on Syntax Error, prints infinite spam nearby #125367
These corner weren't quite so broken till after Python 3.12
Activity
SnoopJ commentedon Dec 9, 2022
I believe this happens because the keyboard interrupt puts you in post-mortem debugging mode, so the subsequent
quitcommand does not apply to the original instance ofPdb, which continues its loop.This infinite loop also happens with an empty file or one containing no statements (but not "noninteractive scripts" that contain at least one statement), so the trace function that powers the debugger never fires. I'm not sure why/how the older versions started with a prompt even when no statements are present, though.
SnoopJ commentedon Dec 10, 2022
I've had a closer look at this, the change in behavior between 3.10 and 3.11 appears to be caused by #94552, although I don't really understand which part of
pdb.pythat's interacting with or how to resolve it.Merge branch 'main' into pythongh-100141
Merge branch 'main' into pythongh-100141
SonOfLilit commentedon Jul 8, 2023
I found the bug and wrote a PR, core dev feedback needed :-)
pelavarre commentedon Sep 21, 2024
Do we know where this Bug is?
Do we all know the test of: python3 -m pdb /dev/null
still does hang some Python's today?
Exact same cause as before, or a new escape, while none of us add this test?
Three examples =>
1 ) macOS latest fails this test
Calling -m pdb to check Python Syntax hangs in this same way on a File of nothing but Comments and Line Breaks
But go wander into the right corner of the Python world, and this problem does not repro out there. For example
Am I helping? Can I help?
pelavarre commentedon Oct 12, 2024
Leaving this corner untested made it worse eventually
Python 3.13 came out in Oct/2024, so I reran our tests there. I've now reported the process exit return code gone wrong on Syntax Error's, but also mentioned our infinite spam observations here, up now into
These corner weren't quite so broken till after Python 3.12
picnixz commentedon Oct 12, 2024
cc @gaogaotiantian as the pdb expert
gh-100141: Allow pdb to deal with empty file (#125425)
pythongh-100141: Allow pdb to deal with empty file (pythonGH-125425)
pythongh-100141: Allow pdb to deal with empty file (pythonGH-125425)
gaogaotiantian commentedon Oct 15, 2024
Fixed in #125425
[3.13] gh-100141: Allow pdb to deal with empty file (GH-125425) (#125536
[3.12] gh-100141: Allow pdb to deal with empty file (GH-125425) (#125537