Skip to content

Commit e245ed7

Browse files
gh-118714: Make the pdb post-mortem restart/quit behavior more reasonable (#118725)
1 parent f8373db commit e245ed7

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

Lib/pdb.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2481,9 +2481,12 @@ def main():
24812481
traceback.print_exception(e, colorize=_colorize.can_colorize())
24822482
print("Uncaught exception. Entering post mortem debugging")
24832483
print("Running 'cont' or 'step' will restart the program")
2484-
pdb.interaction(None, e)
2485-
print(f"Post mortem debugger finished. The {target} will "
2486-
"be restarted")
2484+
try:
2485+
pdb.interaction(None, e)
2486+
except Restart:
2487+
print("Restarting", target, "with arguments:")
2488+
print("\t" + " ".join(sys.argv[1:]))
2489+
continue
24872490
if pdb._user_requested_quit:
24882491
break
24892492
print("The program finished and will be restarted")

Lib/test/test_pdb.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3545,6 +3545,23 @@ def change_file(content, filename):
35453545
# the file as up to date
35463546
self.assertNotIn("WARNING:", stdout)
35473547

3548+
def test_post_mortem_restart(self):
3549+
script = """
3550+
def foo():
3551+
raise ValueError("foo")
3552+
foo()
3553+
"""
3554+
3555+
commands = """
3556+
continue
3557+
restart
3558+
continue
3559+
quit
3560+
"""
3561+
3562+
stdout, stderr = self.run_pdb_script(script, commands)
3563+
self.assertIn("Restarting", stdout)
3564+
35483565
def test_relative_imports(self):
35493566
self.module_name = 't_main'
35503567
os_helper.rmtree(self.module_name)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Allow ``restart`` in post-mortem debugging of :mod:`pdb`. Removed restart message
2+
when the user quits pdb from post-mortem mode.

0 commit comments

Comments
 (0)