From 2c1208ba3847b1cbbf7469b7fca1911cdb7306c5 Mon Sep 17 00:00:00 2001 From: An Long Date: Sun, 5 Jul 2026 15:20:51 +0900 Subject: [PATCH 1/3] Preserve cProfile enable errors --- Lib/test/test_profiling/test_tracing_profiler.py | 5 +++-- Modules/_lsprof.c | 1 - 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Lib/test/test_profiling/test_tracing_profiler.py b/Lib/test/test_profiling/test_tracing_profiler.py index 3668e24e073ce4d..e9f55613b6cfbb8 100644 --- a/Lib/test/test_profiling/test_tracing_profiler.py +++ b/Lib/test/test_profiling/test_tracing_profiler.py @@ -118,8 +118,9 @@ def test_second_profiler(self): pr = self.profilerclass() pr2 = self.profilerclass() pr.enable() - self.assertRaises(ValueError, pr2.enable) - pr.disable() + self.addCleanup(pr.disable) + msg = f"tool {sys.monitoring.PROFILER_ID} is already in use" + self.assertRaisesRegex(ValueError, msg, pr2.enable) def test_throw(self): """ diff --git a/Modules/_lsprof.c b/Modules/_lsprof.c index 3d341a336ab22e6..4e50ca64f59af22 100644 --- a/Modules/_lsprof.c +++ b/Modules/_lsprof.c @@ -821,7 +821,6 @@ _lsprof_Profiler_enable_impl(ProfilerObject *self, int subcalls, "use_tool_id", "is", self->tool_id, "cProfile"); if (check == NULL) { - PyErr_Format(PyExc_ValueError, "Another profiling tool is already active"); goto error; } Py_DECREF(check); From 419a4c0bb0f6c227045af1c66c1773cfb16827ee Mon Sep 17 00:00:00 2001 From: An Long Date: Sun, 5 Jul 2026 16:09:35 +0900 Subject: [PATCH 2/3] Blurb it --- .../next/Library/2026-07-05-16-09-31.gh-issue-153068.huY9Jh.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2026-07-05-16-09-31.gh-issue-153068.huY9Jh.rst diff --git a/Misc/NEWS.d/next/Library/2026-07-05-16-09-31.gh-issue-153068.huY9Jh.rst b/Misc/NEWS.d/next/Library/2026-07-05-16-09-31.gh-issue-153068.huY9Jh.rst new file mode 100644 index 000000000000000..47c2538c5174324 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-07-05-16-09-31.gh-issue-153068.huY9Jh.rst @@ -0,0 +1,2 @@ +Fix :meth:`cProfile.Profile.enable` to no longer overwrite errors from +:mod:`sys.monitoring`. From 8dbb9eadadbdf4a52eb59f0821a94d67851edcb4 Mon Sep 17 00:00:00 2001 From: An Long Date: Sun, 5 Jul 2026 16:46:00 +0900 Subject: [PATCH 3/3] fix news entry --- .../next/Library/2026-07-05-16-09-31.gh-issue-153068.huY9Jh.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2026-07-05-16-09-31.gh-issue-153068.huY9Jh.rst b/Misc/NEWS.d/next/Library/2026-07-05-16-09-31.gh-issue-153068.huY9Jh.rst index 47c2538c5174324..accf6e99cd6434d 100644 --- a/Misc/NEWS.d/next/Library/2026-07-05-16-09-31.gh-issue-153068.huY9Jh.rst +++ b/Misc/NEWS.d/next/Library/2026-07-05-16-09-31.gh-issue-153068.huY9Jh.rst @@ -1,2 +1,2 @@ -Fix :meth:`cProfile.Profile.enable` to no longer overwrite errors from +Fix :meth:`!cProfile.Profile.enable` to no longer overwrite errors from :mod:`sys.monitoring`.