Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pdb loops endlessly on non-interactive scripts #100141

Closed
nphilipp opened this issue Dec 9, 2022 · 7 comments
Closed

Pdb loops endlessly on non-interactive scripts #100141

nphilipp opened this issue Dec 9, 2022 · 7 comments
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@nphilipp
Copy link

nphilipp commented Dec 9, 2022

Bug report

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

Linked PRs

@nphilipp nphilipp added the type-bug An unexpected behavior, bug, or error label Dec 9, 2022
@SnoopJ
Copy link
Contributor

SnoopJ commented Dec 9, 2022

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.

@SnoopJ
Copy link
Contributor

SnoopJ commented 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.py that's interacting with or how to resolve it.

SonOfLilit added a commit to SonOfLilit/cpython that referenced this issue Jul 6, 2023
SonOfLilit added a commit to SonOfLilit/cpython that referenced this issue Jul 8, 2023
@SonOfLilit
Copy link

I found the bug and wrote a PR, core dev feedback needed :-)

@iritkatriel iritkatriel added the stdlib Python modules in the Lib dir label Nov 26, 2023
@pelavarre
Copy link

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

$ </dev/null python3 -m pdb /dev/null 2>&1 |head -3
> /dev/null(1)<module>()
(Pdb) 
$ 
$ python3 --version
Python 3.10.12
$ uname
Linux
$ 

Am I helping? Can I help?

@pelavarre
Copy link

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

@picnixz
Copy link
Contributor

picnixz commented Oct 12, 2024

cc @gaogaotiantian as the pdb expert

miss-islington pushed a commit to miss-islington/cpython that referenced this issue Oct 15, 2024
(cherry picked from commit bb9604b)

Co-authored-by: Tian Gao <gaogaotiantian@hotmail.com>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Oct 15, 2024
(cherry picked from commit bb9604b)

Co-authored-by: Tian Gao <gaogaotiantian@hotmail.com>
@gaogaotiantian
Copy link
Member

Fixed in #125425

gaogaotiantian added a commit that referenced this issue Oct 15, 2024
)

gh-100141: Allow pdb to deal with empty file (GH-125425)
(cherry picked from commit bb9604b)

Co-authored-by: Tian Gao <gaogaotiantian@hotmail.com>
gaogaotiantian added a commit that referenced this issue Oct 15, 2024
)

gh-100141: Allow pdb to deal with empty file (GH-125425)
(cherry picked from commit bb9604b)

Co-authored-by: Tian Gao <gaogaotiantian@hotmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

7 participants