Skip to content

"python3.13 -m pdb" exits zero on Syntax Error, prints infinite spam nearby #125367

Closed

Description

@pelavarre

Bug report

Bug description:

The meaning of "python3 -m pdb" is slowly going wild on short input files? Step-by-step evolving now with no tests deployed to limit how wild it goes?

Four Notes here = Two wrongs we can repro simply, and then two bits of more context

1 )

The process exit return code wrongly comes back as zero in reply to Syntax-Error's, not the nonzero that used to screen out Syntax-Error's, when I upgrade to Python 13 from 12

For example, this M Pdb test of a short SyntaxError

echo alef = >p.py
echo |python3.13 -m pdb p.py >/dev/null 2>&1; echo + exit $? ' # in 13'
echo |python3.12 -m pdb p.py >/dev/null 2>&1; echo + exit $? ' # in 12'

produces the conflicting outputs

+ exit 0  # in 13
+ exit 1  # in 12

We like the old result much better, yes?

2 )

M Pdb tests hang in a loop producing infinite output, after the upgrade to Python 13 from 10

For example, this test of an empty Input File ran happy quickly and concisely, back in the days of 2021 Python 10

$ echo |python3.10 -m pdb /dev/null
> /dev/null(1)<module>()
(Pdb) (Pdb) 
$ 

But in Python 3.13, this same empty test now produces infinitely many copies of a log line, and hangs until you press Control + \

$ echo |python3.13 -m pdb /dev/null
The program finished and will be restarted
The program finished and will be restarted
...

The effects of pressing Control + C instead are not simple. In some Python's, you get multiple chances to press Control + C. In others, it works only the first time. Sometimes Control + D will exit the process after a Control + C. Sometimes it won't. Here I'm reporting from my own living human memory, I've not written out a carefully reproducible survey of all that

"We like the old result much better, yes?"

3 )

I saw these bugs first in macOS, where I take the Python binary from Python Org as it comes out monthly

To make this report, I've gone and tested Linux too. For these bugs, I see that a Python Version gone wrong at macOS also goes wrong in the same way in the same Python Version at Linux. That's comforting

More specifically, I do also see these same bugs in the Linux Gcloud Gshell of my Gmail, after I toss in a few more Linux Python's from DeadSnakes for comparison

apt-cache search python3.10
apt-cache search python3.11
apt-cache search python3.13
sudo add-apt-repository -y ppa:deadsnakes/ppa
sudo apt update
sudo apt install -y python3.10
sudo apt install -y python3.11
sudo apt install -y python3.13

I haven't tested Python3.10 at macOS myself

4 )

Thank you for believing I could help

Am I helping? Can I help more?

CPython versions tested on:

3.13

Operating systems tested on:

Linux, macOS

Activity

  1. added
    stdlibStandard Library Python modules in the Lib/ directory
    on Oct 12, 2024
  2. ZeroIntensity commented on Oct 12, 2024

    @ZeroIntensity
    Member
  3. gaogaotiantian commented on Oct 13, 2024

    @gaogaotiantian
    Member

    For the first issue, no I don't believe the old behavior is better. SyntaxError, like any other exceptions, is just an exception. The exit code of python -m pdb should be the status of pdb, not the script it's debugging. If your script raise a run-time exception, python -m pdb won't have a non-zero exit code. I don't believe raise ValueError() and raise SyntaxError should have different return code, or even different behavior to pdb.

    For the second issue, it's a very rare case. I agree the result is not ideal and I'll look into it and see if we can make it better (at least not stuck in an infinite loop).

  4. gaogaotiantian commented on Oct 15, 2024

    @gaogaotiantian
    Member

    The infinite spam of empty file is fixed in #125425. As I mentioned above, I believe the exit code is actually more consistent than the previous result. So I'll close this for now, feel free to reopen it or open a new issue if you find other behavior that's not ideal.

  5. ZeroIntensity commented on Oct 15, 2024

    @ZeroIntensity
    Member

    Thank you, Tian, and thanks @pelavarre for the report!

  6. pelavarre commented on Oct 25, 2024

    @pelavarre
    Author

    You're most welcome for my reporting! My thanks due all around for the considerable work you gave in reply

    If people do land here when they first stumble into "python3 -m pdb" exiting zero more often nowadays than years ago . . .

    They might next should adopt scraping output from "-m py_compile" instead, as their new gate against SyntaxWarning and SyntaxError

    % cat p.py
    if False:
        1(123)
    % 
    
    % python3.13 -m py_compile p.py
    p.py:2: SyntaxWarning: 'int' object is not callable; perhaps you missed a comma?
      1(123)
    % echo + exit $?
    + exit 0
    % 
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

3.13only security fixesstdlibStandard 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