This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: cannot quit pdb when there is a syntax error in the debuggee (must kill it)
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.6, Python 3.4, Python 3.5, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: asvetlov, georg.brandl, python-dev, rurpy2, terry.reedy, xdegaye
Priority: normal Keywords: patch

Created on 2012-10-09 19:33 by xdegaye, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
pdbloopfix.diff terry.reedy, 2015-09-04 18:19 review
pdb_syntax_error.patch xdegaye, 2015-09-05 10:08 review
Messages (7)
msg172508 - (view) Author: Xavier de Gaye (xdegaye) * (Python triager) Date: 2012-10-09 19:33
$ tmp=`mktemp /tmp/foo.XXXXXXXXXX`; echo 'def foo: pass' > $tmp; python3 -m pdb $tmp; rm $tmp
Traceback (most recent call last):
  File "/usr/local/lib/python3.2/pdb.py", line 1556, in main
    pdb._runscript(mainpyfile)
  File "/usr/local/lib/python3.2/pdb.py", line 1437, in _runscript
    self.run(statement)
  File "/usr/local/lib/python3.2/bdb.py", line 392, in run
    exec(cmd, globals, locals)
  File "<string>", line 1, in <module>
  File "/tmp/foo.iLhPYHBZrF", line 1
    def foo: pass
           ^
SyntaxError: invalid syntax
Uncaught exception. Entering post mortem debugging
Running 'cont' or 'step' will restart the program
> <string>(1)<module>()
(Pdb) quit
Post mortem debugger finished. The /tmp/foo.iLhPYHBZrF will be restarted
Traceback (most recent call last):
  File "/usr/local/lib/python3.2/pdb.py", line 1556, in main
    pdb._runscript(mainpyfile)
  File "/usr/local/lib/python3.2/pdb.py", line 1437, in _runscript
    self.run(statement)
  File "/usr/local/lib/python3.2/bdb.py", line 392, in run
    exec(cmd, globals, locals)
  File "<string>", line 1, in <module>
  File "/tmp/foo.iLhPYHBZrF", line 1
    def foo: pass
           ^
SyntaxError: invalid syntax
Uncaught exception. Entering post mortem debugging
Running 'cont' or 'step' will restart the program
> <string>(1)<module>()
(Pdb) --KeyboardInterrupt--
(Pdb)
msg175970 - (view) Author: rurpy (rurpy2) Date: 2012-11-19 21:54
This continues to be a problem on Python-3.3.0
msg176274 - (view) Author: Xavier de Gaye (xdegaye) * (Python triager) Date: 2012-11-24 10:49
See how this is fixed at
http://code.google.com/p/pdb-clone/source/detail?r=0d4d905c6e0aa9c47611dbae514d3f7f53776dcb
msg249797 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2015-09-04 17:49
Reported again in #24957

Xavier, your link is out of date.
msg249802 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2015-09-04 18:19
Simple fix attached.  I copied the exit code from this part of the 'while True:' loop.

        try:
            pdb._runscript(mainpyfile)
            if pdb._user_requested_quit:
                break
            print("The program finished and will be restarted")

I am not sure if the conditional is still needed there.

Xavier, if you have a better patch, please upload it.
msg249900 - (view) Author: Xavier de Gaye (xdegaye) * (Python triager) Date: 2015-09-05 10:08
Slightly better in that pdb exits in case of a syntax error instead of proposing to restart the program which does not make sense.

A test case is included.
msg249949 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2015-09-05 23:19
New changeset 26c4db1a0aea by Terry Jan Reedy in branch '2.7':
Issue #16180: Exit pdb if file has syntax error, instead of trapping user
https://hg.python.org/cpython/rev/26c4db1a0aea

New changeset 2d4aac2ab253 by Terry Jan Reedy in branch '3.4':
Issue #16180: Exit pdb if file has syntax error, instead of trapping user
https://hg.python.org/cpython/rev/2d4aac2ab253
History
Date User Action Args
2022-04-11 14:57:37adminsetgithub: 60384
2015-09-05 23:20:31terry.reedysetstatus: open -> closed
resolution: fixed
stage: test needed -> resolved
2015-09-05 23:19:05python-devsetnosy: + python-dev
messages: + msg249949
2015-09-05 10:09:00xdegayesetfiles: + pdb_syntax_error.patch

messages: + msg249900
2015-09-04 18:19:06terry.reedysetfiles: + pdbloopfix.diff
keywords: + patch
messages: + msg249802
2015-09-04 17:50:44terry.reedylinkissue24957 superseder
2015-09-04 17:49:44terry.reedysetversions: + Python 2.7, Python 3.4, Python 3.5, Python 3.6, - Python 3.3
nosy: + georg.brandl, terry.reedy

messages: + msg249797

stage: test needed
2012-12-05 11:08:21asvetlovsetnosy: + asvetlov
2012-11-24 10:49:13xdegayesetmessages: + msg176274
2012-11-19 21:54:52rurpy2setnosy: + rurpy2

messages: + msg175970
versions: + Python 3.3, - Python 3.2
2012-10-09 19:33:24xdegayecreate