diff options
author | Mario Corchero <mcorcherojim@bloomberg.net> | 2020-11-04 09:27:43 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-04 09:27:43 (GMT) |
commit | 0001a1b69ecda47b0406daa88c2943877580bcae (patch) | |
tree | 3b9a00c8fc1c9602aa77313e029330b43d81bd93 /Lib/threading.py | |
parent | db6434c474f7389a98b8118ca87fca988416bf33 (diff) | |
download | cpython-0001a1b69ecda47b0406daa88c2943877580bcae.zip cpython-0001a1b69ecda47b0406daa88c2943877580bcae.tar.gz cpython-0001a1b69ecda47b0406daa88c2943877580bcae.tar.bz2 |
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/threading.py')
-rw-r--r-- | Lib/threading.py | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/Lib/threading.py b/Lib/threading.py index 06c77f7..d4fe649 100644 --- a/Lib/threading.py +++ b/Lib/threading.py @@ -28,7 +28,7 @@ __all__ = ['get_ident', 'active_count', 'Condition', 'current_thread', 'Event', 'Lock', 'RLock', 'Semaphore', 'BoundedSemaphore', 'Thread', 'Barrier', 'BrokenBarrierError', 'Timer', 'ThreadError', 'setprofile', 'settrace', 'local', 'stack_size', - 'excepthook', 'ExceptHookArgs'] + 'excepthook', 'ExceptHookArgs', 'gettrace', 'getprofile'] # Rename some stuff so "from threading import *" is safe _start_new_thread = _thread.start_new_thread @@ -65,6 +65,10 @@ def setprofile(func): global _profile_hook _profile_hook = func +def getprofile(): + """Get the profiler function as set by threading.setprofile().""" + return _profile_hook + def settrace(func): """Set a trace function for all threads started from the threading module. @@ -75,6 +79,10 @@ def settrace(func): global _trace_hook _trace_hook = func +def gettrace(): + """Get the trace function as set by threading.settrace().""" + return _trace_hook + # Synchronization classes Lock = _allocate_lock |