From 45a2d1ccd071a79a07b71c7187d50c25afa69432 Mon Sep 17 00:00:00 2001 From: Tian Gao Date: Tue, 20 Oct 2026 10:18:44 -0700 Subject: [PATCH 1/3] Ignore set_trace() when we are already in pdb --- Lib/bdb.py | 7 +++++++ Lib/test/test_pdb.py | 12 ++++++++++++ 2 files changed, 19 insertions(+) diff --git a/Lib/bdb.py b/Lib/bdb.py index f0601913ab3c8d..179111a6ae9901 100644 --- a/Lib/bdb.py +++ b/Lib/bdb.py @@ -600,6 +600,13 @@ def set_trace(self, frame=None): If frame is not specified, debugging starts from caller's frame. """ + + if self.enterframe is not None: + # If self.enterframe is not None, it means we are already in + # dispatched functions. Tracing is disabled when calling a + # trace function, so we just skip this set_trace() call. + return + self.stop_trace() if frame is None: frame = sys._getframe().f_back diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py index 8876b3f5ce37a3..697fb22e6ea8c2 100644 --- a/Lib/test/test_pdb.py +++ b/Lib/test/test_pdb.py @@ -4950,6 +4950,18 @@ def foo(): stdout, _ = self._run_script(script, commands) self.assertIn("42", stdout) + def test_nested_set_trace(self): + # Calling breakpoint() in pdb prompt should just be ignored. + script = "breakpoint()" + commands = """ + breakpoint() + p 40 + 2 + c + """ + stdout, stderr = self._run_script(script, commands) + self.assertIn('42', stdout) + self.assertEqual(stderr, '') + def test_readline_not_imported(self): """GH-138860 Directly or indirectly importing readline might deadlock a subprocess From 1a43fa83c6d48a8384644b76e1ceace3c8c8c4f4 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Tue, 20 Oct 2026 17:29:20 +0000 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../next/Library/2026-10-20-17-29-14.gh-issue-138641.FN6qM0.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2026-10-20-17-29-14.gh-issue-138641.FN6qM0.rst diff --git a/Misc/NEWS.d/next/Library/2026-10-20-17-29-14.gh-issue-138641.FN6qM0.rst b/Misc/NEWS.d/next/Library/2026-10-20-17-29-14.gh-issue-138641.FN6qM0.rst new file mode 100644 index 00000000000000..af116c97c896d0 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-10-20-17-29-14.gh-issue-138641.FN6qM0.rst @@ -0,0 +1 @@ +Ignore :func:`pdb.set_trace()` when running it directly from :mod:`pdb` prompts. From 2ab55192369a243e235f7f18518c93ca1a0d5e6f Mon Sep 17 00:00:00 2001 From: Tian Gao Date: Tue, 20 Oct 2026 10:41:46 -0700 Subject: [PATCH 3/3] Fix news --- .../next/Library/2026-10-20-17-29-14.gh-issue-138641.FN6qM0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2026-10-20-17-29-14.gh-issue-138641.FN6qM0.rst b/Misc/NEWS.d/next/Library/2026-10-20-17-29-14.gh-issue-138641.FN6qM0.rst index af116c97c896d0..6d9ac174282839 100644 --- a/Misc/NEWS.d/next/Library/2026-10-20-17-29-14.gh-issue-138641.FN6qM0.rst +++ b/Misc/NEWS.d/next/Library/2026-10-20-17-29-14.gh-issue-138641.FN6qM0.rst @@ -1 +1 @@ -Ignore :func:`pdb.set_trace()` when running it directly from :mod:`pdb` prompts. +Ignore :func:`pdb.set_trace` when called directly at the :mod:`pdb` prompt.