From: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Date: Tue, 7 Jul 2026 00:03:12 +0000 (+0200) Subject: [3.14] gh-153068: Preserve cprofile enable errors (GH-153070) (#153242) X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f57837a3f157f230e2f49d1c7d8e0987b1d942e1;p=thirdparty%2FPython%2Fcpython.git [3.14] gh-153068: Preserve cprofile enable errors (GH-153070) (#153242) --- diff --git a/Lib/test/test_cprofile.py b/Lib/test/test_cprofile.py index 57e818b1c68b..c903ecd5f657 100644 --- a/Lib/test/test_cprofile.py +++ b/Lib/test/test_cprofile.py @@ -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 index 000000000000..accf6e99cd64 --- /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`. diff --git a/Modules/_lsprof.c b/Modules/_lsprof.c index 73602723d19b..412909cd9bf3 100644 --- a/Modules/_lsprof.c +++ b/Modules/_lsprof.c @@ -819,7 +819,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);