Skip to content

gh-118714: Make the pdb post-mortem restart/quit behavior more reasonable #118725

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

Merged
merged 4 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions Lib/pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -2441,9 +2441,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 @@ -3409,6 +3409,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 @@
Make the :mod:`pdb` post-mortem restart/quit message match the behavior
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't very clear. Also, it seems inconsistent with the title of this PR. Are you changing the behaviour (as the title says) or changing the message to match the behaviour?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both behavior and message were changed. There were two cases involved, both under post-mortem debugging:

  1. If the user does restart, it actually restarts the program, instead of raising an error and exit. (This is the behavior change).
  2. If the user does quit, it quits the program without printing the line saying "we'll restart the program".

I think I should make the behavior change clearer (it's considered a bug fix because quitting the debugger when doing restart feels wrong).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forgot to change this after the review. Just changed it. Let me know if you think this could be better.

Loading