Depending on whether you just want to keep track of one thread while other threads are running, or if you want to stop other threads, I can think of two solutions. If other threads should run without tracing, just ask the trace command to first check the current thread id and perform a trace operation if the thread is the one you are interested in:
def dotrace(): if tracing and threading.current_thread() == the_traced_thread: ... do the tracing ...
If instead other threads should stop during tracking, you can make your trace work as a stop for other threads by adding something like:
def dotrace(): while tracing and threading.current_thread() != the_traced_thread: time.sleep(0.01) if tracing and threading.current_thread() == the_traced_thread: ... do the tracing ...
Of course, only the last operations will work as a stop in the latter case, so that other threads can continue to work until they end, or they will not trace anything.
Basically, you will only stop other threads that you control, not all other threads. I would say that this is good, because it increases the likelihood that the program will remain functional (some of the libraries and frameworks used may need other threads for the thread that actually works for it), but, of course, YMMV.
source share