Skip to content

Commit

Permalink
pythongh-118714: Make the pdb post-mortem restart/quit behavior more …
Browse files Browse the repository at this point in the history
…reasonable (pythonGH-118725)

(cherry picked from commit e245ed7)

Co-authored-by: Tian Gao <gaogaotiantian@hotmail.com>
  • Loading branch information
gaogaotiantian authored and miss-islington committed Jul 3, 2024
1 parent 3d4e533 commit 2a0d7f4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
9 changes: 6 additions & 3 deletions Lib/pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -2460,9 +2460,12 @@ def main():
traceback.print_exception(e, colorize=_colorize.can_colorize())
print("Uncaught exception. Entering post mortem debugging")
print("Running 'cont' or 'step' will restart the program")
pdb.interaction(None, e)
print(f"Post mortem debugger finished. The {target} will "
"be restarted")
try:
pdb.interaction(None, e)
except Restart:
print("Restarting", target, "with arguments:")
print("\t" + " ".join(sys.argv[1:]))
continue
if pdb._user_requested_quit:
break
print("The program finished and will be restarted")
Expand Down
17 changes: 17 additions & 0 deletions Lib/test/test_pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -3492,6 +3492,23 @@ def change_file(content, filename):
# the file as up to date
self.assertNotIn("WARNING:", stdout)

def test_post_mortem_restart(self):
script = """
def foo():
raise ValueError("foo")
foo()
"""

commands = """
continue
restart
continue
quit
"""

stdout, stderr = self.run_pdb_script(script, commands)
self.assertIn("Restarting", stdout)

def test_relative_imports(self):
self.module_name = 't_main'
os_helper.rmtree(self.module_name)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Allow ``restart`` in post-mortem debugging of :mod:`pdb`. Removed restart message
when the user quits pdb from post-mortem mode.

0 comments on commit 2a0d7f4

Please sign in to comment.