Skip to content

Commit 78e9fdb

Browse files
[3.15] gh-153068: Preserve cprofile enable errors (GH-153070) (#153241)
1 parent 81986cb commit 78e9fdb

3 files changed

Lines changed: 5 additions & 3 deletions

File tree

Lib/test/test_profiling/test_tracing_profiler.py

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

123124
def test_throw(self):
124125
"""
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
@@ -821,7 +821,6 @@ _lsprof_Profiler_enable_impl(ProfilerObject *self, int subcalls,
821821
"use_tool_id", "is",
822822
self->tool_id, "cProfile");
823823
if (check == NULL) {
824-
PyErr_Format(PyExc_ValueError, "Another profiling tool is already active");
825824
goto error;
826825
}
827826
Py_DECREF(check);

0 commit comments

Comments
 (0)