Skip to content

Commit 13c7a8d

Browse files
aiskmiss-islington
authored andcommitted
gh-153068: Preserve cprofile enable errors (GH-153070)
(cherry picked from commit dea93ce) Co-authored-by: An Long <aisk@users.noreply.github.com>
1 parent a9a91d0 commit 13c7a8d

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
@@ -118,8 +118,9 @@ def test_second_profiler(self):
118118
pr = self.profilerclass()
119119
pr2 = self.profilerclass()
120120
pr.enable()
121-
self.assertRaises(ValueError, pr2.enable)
122-
pr.disable()
121+
self.addCleanup(pr.disable)
122+
msg = f"tool {sys.monitoring.PROFILER_ID} is already in use"
123+
self.assertRaisesRegex(ValueError, msg, pr2.enable)
123124

124125
def test_throw(self):
125126
"""
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
@@ -819,7 +819,6 @@ _lsprof_Profiler_enable_impl(ProfilerObject *self, int subcalls,
819819
"use_tool_id", "is",
820820
self->tool_id, "cProfile");
821821
if (check == NULL) {
822-
PyErr_Format(PyExc_ValueError, "Another profiling tool is already active");
823822
goto error;
824823
}
825824
Py_DECREF(check);

0 commit comments

Comments
 (0)