diff options
author | Mario Corchero <mcorcherojim@bloomberg.net> | 2020-11-04 10:27:43 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-04 09:27:43 +0000 |
commit | 0001a1b69ecda47b0406daa88c2943877580bcae (patch) | |
tree | 3b9a00c8fc1c9602aa77313e029330b43d81bd93 /Lib/test/test_threading.py | |
parent | db6434c474f7389a98b8118ca87fca988416bf33 (diff) | |
download | cpython-0001a1b69ecda47b0406daa88c2943877580bcae.tar.gz cpython-0001a1b69ecda47b0406daa88c2943877580bcae.zip |
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.
Diffstat (limited to 'Lib/test/test_threading.py')
-rw-r--r-- | Lib/test/test_threading.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/Lib/test/test_threading.py b/Lib/test/test_threading.py index 2f0f3ae0946..e0e5406ac26 100644 --- a/Lib/test/test_threading.py +++ b/Lib/test/test_threading.py @@ -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): |