Skip to content

Pdb loops endlessly on non-interactive scripts #100141

Closed

Description

@nphilipp

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

Activity

  1. SnoopJ commented on Dec 9, 2022

    @SnoopJ
    Contributor

    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.

  2. SnoopJ commented on Dec 10, 2022

    @SnoopJ
    Contributor

    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.

  3. SonOfLilit commented on Jul 8, 2023

    @SonOfLilit

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

  4. added
    stdlibStandard Library Python modules in the Lib/ directory
    on Nov 26, 2023
  5. pelavarre commented on Sep 21, 2024

    @pelavarre

    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?

  6. pelavarre commented on Oct 12, 2024

    @pelavarre

    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

  7. picnixz commented on Oct 12, 2024

    @picnixz
    Member

    cc @gaogaotiantian as the pdb expert

  8. added a commit that references this issue on Oct 15, 2024
  9. added 2 commits that reference this issue on Oct 15, 2024
  10. gaogaotiantian commented on Oct 15, 2024

    @gaogaotiantian
    Member

    Fixed in #125425

  11. added 2 commits that reference this issue on Oct 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions