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
Unable to exit pdb when script becomes invalid #75304
Comments
Similar to bpo-16180 and possible a duplicate of bpo-14743, if the script being run under pdb becomes invalid such as through a chdir operation, pdb will get trapped in a loop, catching its own exception. $ mkdir foo
$ cat > foo/script.py
import os
os.chdir('foo')
$ python -m pdb foo/script.py
> /Users/jaraco/Dropbox/code/privacymate/harvester/foo/script.py(1)<module>()
-> import os
(Pdb) c
The program finished and will be restarted
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/pdb.py", line 1667, in main
pdb._runscript(mainpyfile)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/pdb.py", line 1545, in _runscript
with open(filename, "rb") as fp:
FileNotFoundError: [Errno 2] No such file or directory: 'foo/script.py'
Uncaught exception. Entering post mortem debugging
Running 'cont' or 'step' will restart the program
> /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/pdb.py(1545)_runscript()
-> with open(filename, "rb") as fp:
(Pdb) q
Post mortem debugger finished. The foo/script.py will be restarted
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/pdb.py", line 1667, in main
pdb._runscript(mainpyfile)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/pdb.py", line 1545, in _runscript
with open(filename, "rb") as fp:
FileNotFoundError: [Errno 2] No such file or directory: 'foo/script.py'
Uncaught exception. Entering post mortem debugging
Running 'cont' or 'step' will restart the program
> /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/pdb.py(1545)_runscript()
-> with open(filename, "rb") as fp:
(Pdb) q
Post mortem debugger finished. The foo/script.py will be restarted
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/pdb.py", line 1667, in main
pdb._runscript(mainpyfile)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/pdb.py", line 1545, in _runscript
with open(filename, "rb") as fp:
FileNotFoundError: [Errno 2] No such file or directory: 'foo/script.py'
Uncaught exception. Entering post mortem debugging
Running 'cont' or 'step' will restart the program
> /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/pdb.py(1545)_runscript()
-> with open(filename, "rb") as fp:
(Pdb) I suggest PDB should always pass exceptions when the stack trace terminates in the pdb module. |
Another way to reproduce this that will continue to work once bpo-42383 is fixed is to delete or move the script while it's being debugged. |
This does not reproduce in main anymore because the script path is remembered before it's being executed. |
I believe the issue is still reproducible. I reproduced in on Python 3.12.1, this time using the technique of deleting the file:
I've tested on main as well, at 7fdd423, and indeed the repro with deleting the file no longer falls into the loop:
|
Yeah it's fixed in main but not 3.12. It's also not a trivial fix so I'm not sure if we will backport the fix. The issue has been there for more than 6 years anyway. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: