bpo-42251: Add gettrace and getprofile to threading (GH-23125)

This allows to retrieve the functions that were set in these two, which might differ from sys.gettrace and sys.getprofile within a thread.
This commit is contained in:
Mario Corchero 2020-11-04 10:27:43 +01:00 committed by GitHub
parent db6434c474
commit 0001a1b69e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 61 additions and 1 deletions

View file

@ -765,6 +765,27 @@ class ThreadTests(BaseTestCase):
finally:
sys.settrace(old_trace)
def test_gettrace(self):
def noop_trace(frame, event, arg):
# no operation
return noop_trace
old_trace = threading.gettrace()
try:
threading.settrace(noop_trace)
trace_func = threading.gettrace()
self.assertEqual(noop_trace,trace_func)
finally:
threading.settrace(old_trace)
def test_getprofile(self):
def fn(*args): pass
old_profile = threading.getprofile()
try:
threading.setprofile(fn)
self.assertEqual(fn, threading.getprofile())
finally:
threading.setprofile(old_profile)
@cpython_only
def test_shutdown_locks(self):
for daemon in (False, True):