]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-153068: Preserve cprofile enable errors (#153070)
authorAn Long <aisk@users.noreply.github.com>
Mon, 6 Jul 2026 23:36:26 +0000 (08:36 +0900)
committerGitHub <noreply@github.com>
Mon, 6 Jul 2026 23:36:26 +0000 (00:36 +0100)
Lib/test/test_profiling/test_tracing_profiler.py
Misc/NEWS.d/next/Library/2026-07-05-16-09-31.gh-issue-153068.huY9Jh.rst [new file with mode: 0644]
Modules/_lsprof.c

index 3668e24e073ce4daab34dfc0c6f180acd3c8d8af..e9f55613b6cfbb8c92cb6a3f6b7e7db3d3164508 100644 (file)
@@ -118,8 +118,9 @@ class CProfileTest(ProfileTest):
         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/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 (file)
index 0000000..accf6e9
--- /dev/null
@@ -0,0 +1,2 @@
+Fix :meth:`!cProfile.Profile.enable` to no longer overwrite errors from
+:mod:`sys.monitoring`.
index 3d341a336ab22e622c5fa0b7a0a208a886098642..4e50ca64f59af225e75ca15d55df141f5e50d78a 100644 (file)
@@ -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);