File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -90,6 +90,20 @@ \section{\module{threading} ---
9090A thread that executes a function after a specified interval has passed.
9191\end {classdesc* }
9292
93+ \begin {funcdesc }{settrace}{func}
94+ Set a trace function \index {trace function} for all threads started
95+ from the \module {threading} module. The \var {func} will be passed to
96+ \cfuntion {sys.settrace} for each thread, before its \method {run}
97+ method is called.
98+ \end {funcdesc }
99+
100+ \begin {funcdesc }{setprofile}{func}
101+ Set a profile function \index {profile function} for all threads started
102+ from the \module {threading} module. The \var {func} will be passed to
103+ \cfuntion {sys.setprofile} for each thread, before its \method {run}
104+ method is called.
105+ \end {funcdesc }
106+
93107Detailed interfaces for the objects are documented below.
94108
95109The design of this module is loosely based on Java's threading model.
Original file line number Diff line number Diff line change @@ -52,6 +52,18 @@ def __init__(self, verbose=None):
5252 def _note (self , * args ):
5353 pass
5454
55+ # Support for profile and trace hooks
56+
57+ _profile_hook = None
58+ _trace_hook = None
59+
60+ def setprofile (func ):
61+ global _profile_hook
62+ _profile_hook = func
63+
64+ def settrace (func ):
65+ global _trace_hook
66+ _trace_hook = func
5567
5668# Synchronization classes
5769
@@ -408,6 +420,14 @@ def __bootstrap(self):
408420 _active_limbo_lock .release ()
409421 if __debug__ :
410422 self ._note ("%s.__bootstrap(): thread started" , self )
423+
424+ if _trace_hook :
425+ self ._note ("%s.__bootstrap(): registering trace hook" , self )
426+ _sys .settrace (_trace_hook )
427+ if _profile_hook :
428+ self ._note ("%s.__bootstrap(): registering profile hook" , self )
429+ _sys .setprofile (_profile_hook )
430+
411431 try :
412432 self .run ()
413433 except SystemExit :
You can’t perform that action at this time.
0 commit comments