mirror of
https://github.com/python/cpython.git
synced 2025-11-08 09:32:01 +00:00
[3.13] gh-137400: Fix thread-safety issues when profiling all threads (gh-137518) (gh-137733)
There were a few thread-safety issues when profiling or tracing all
threads via PyEval_SetProfileAllThreads or PyEval_SetTraceAllThreads:
* The loop over thread states could crash if a thread exits concurrently
(in both the free threading and default build)
* The modification of `c_profilefunc` and `c_tracefunc` wasn't
thread-safe on the free threading build.
(cherry picked from commit a10152f8fd)
This commit is contained in:
parent
f6186a3709
commit
16d2e97cf3
12 changed files with 29814 additions and 29714 deletions
|
|
@ -193,6 +193,32 @@ def during_threads(self):
|
|||
self.set = not self.set
|
||||
|
||||
|
||||
@threading_helper.requires_working_threading()
|
||||
class SetProfileAllThreadsMultiThreaded(InstrumentationMultiThreadedMixin, TestCase):
|
||||
"""Uses threading.setprofile_all_threads and repeatedly toggles instrumentation on and off"""
|
||||
|
||||
def setUp(self):
|
||||
self.set = False
|
||||
self.called = False
|
||||
|
||||
def after_test(self):
|
||||
self.assertTrue(self.called)
|
||||
|
||||
def tearDown(self):
|
||||
threading.setprofile_all_threads(None)
|
||||
|
||||
def trace_func(self, frame, event, arg):
|
||||
self.called = True
|
||||
return self.trace_func
|
||||
|
||||
def during_threads(self):
|
||||
if self.set:
|
||||
threading.setprofile_all_threads(self.trace_func)
|
||||
else:
|
||||
threading.setprofile_all_threads(None)
|
||||
self.set = not self.set
|
||||
|
||||
|
||||
@threading_helper.requires_working_threading()
|
||||
class SetProfileAllMultiThreaded(TestCase):
|
||||
def test_profile_all_threads(self):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue