Skip to content

Commit 33948e7

Browse files
[3.13] gh-153068: Preserve cprofile enable errors (GH-153070) (#153240)
1 parent e36fe36 commit 33948e7

3 files changed

Lines changed: 5 additions & 3 deletions

File tree

Lib/test/test_cprofile.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,9 @@ def test_second_profiler(self):
116116
pr = self.profilerclass()
117117
pr2 = self.profilerclass()
118118
pr.enable()
119-
self.assertRaises(ValueError, pr2.enable)
120-
pr.disable()
119+
self.addCleanup(pr.disable)
120+
msg = f"tool {sys.monitoring.PROFILER_ID} is already in use"
121+
self.assertRaisesRegex(ValueError, msg, pr2.enable)
121122

122123
def test_throw(self):
123124
"""
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix :meth:`!cProfile.Profile.enable` to no longer overwrite errors from
2+
:mod:`sys.monitoring`.

Modules/_lsprof.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -759,7 +759,6 @@ profiler_enable(ProfilerObject *self, PyObject *args, PyObject *kwds)
759759
"use_tool_id", "is",
760760
self->tool_id, "cProfile");
761761
if (check == NULL) {
762-
PyErr_Format(PyExc_ValueError, "Another profiling tool is already active");
763762
goto error;
764763
}
765764
Py_DECREF(check);

0 commit comments

Comments
 (0)