]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-118714: Make the pdb post-mortem restart/quit behavior more reasonable (#118725)
authorTian Gao <gaogaotiantian@hotmail.com>
Wed, 3 Jul 2024 18:30:20 +0000 (11:30 -0700)
committerGitHub <noreply@github.com>
Wed, 3 Jul 2024 18:30:20 +0000 (11:30 -0700)
Lib/pdb.py
Lib/test/test_pdb.py
Misc/NEWS.d/next/Library/2024-05-07-17-38-53.gh-issue-118714.XXKpVZ.rst [new file with mode: 0644]

index 4af16d0a087c8c2851fb311862d61a9da39a578d..85a3aa2e37996fd47d1e40e4a922e82fa1e924f0 100644 (file)
@@ -2481,9 +2481,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")
index 71240157e324a15b5cfdc253a3c3cab316c0d6a9..5c7445574f5d75f8e6c2cbe6d2071d53be9b76b5 100644 (file)
@@ -3545,6 +3545,23 @@ def bœr():
         # 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)
diff --git a/Misc/NEWS.d/next/Library/2024-05-07-17-38-53.gh-issue-118714.XXKpVZ.rst b/Misc/NEWS.d/next/Library/2024-05-07-17-38-53.gh-issue-118714.XXKpVZ.rst
new file mode 100644 (file)
index 0000000..f41baee
--- /dev/null
@@ -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.