]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.13] gh-153068: Preserve cprofile enable errors (GH-153070) (#153240)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Tue, 7 Jul 2026 00:05:43 +0000 (02:05 +0200)
committerGitHub <noreply@github.com>
Tue, 7 Jul 2026 00:05:43 +0000 (00:05 +0000)
Lib/test/test_cprofile.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 acead07d507e4b8518fcdc19d851ba0b05431b8b..c2d9dcab09ed9ec32276166a7fbdc2ececf8832c 100644 (file)
@@ -116,8 +116,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 f23f254c0aa0db3da17e605f0968c6b3cceda85b..fcd856f1035d6cd6f2d76a96a7be0d72a59c1bb7 100644 (file)
@@ -759,7 +759,6 @@ profiler_enable(ProfilerObject *self, PyObject *args, PyObject *kwds)
                                           "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);