Reputation: 88538
I'm debugging a multi-threaded Python program with Wing IDE.
When I press the pause button, it pauses only one thread. I've tried it ten times and it always pauses the same thread, in my case called "ThreadTimer Thread", while the other threads keep on running. I want to pause these other threads so I could step with them. How do I do that?
Upvotes: 1
Views: 783
Reputation: 11
I just name my threads when I create them.
Example thread:
import threading
from threading import Thread
#...
client_address = '192.168.0.2'
#...
thread1 = Thread(target=thread_for_receiving_data,
args=(connection, q, rdots),
name='Connection with '+client_address,
daemon=True)
thread1.start()
Then you can always access the name from inside the thread
print(threading.currentThread())
sys.stdout.flush() #this is essential to print before the thread is completed
You can also list all threads with a specific name
for at in threading.enumerate():
if at.getName().split(' ')[0] == 'Connection':
print('\t'+at.getName())
A similar thing can be done to a process.
Example process:
import multiprocessing
process1 = multiprocessing.Process(target=function,
name='ListenerProcess',
args=(queue, connections, known_clients, readouts),
daemon=True)
process1.start()
With processes it is even better as you can terminate a specific process by its name from outside of it
for child in multiprocessing.active_children():
if child.name == 'ListenerProcess':
print('Terminating:', child, 'PID:', child.pid)
child.terminate()
child.join()
Upvotes: 0
Reputation: 881575
Per the docs, all threads that are running Python code are stopped (by default, i.e., unless you're going out of the way to achieve a different effect). Are the threads that you see as not getting stopped running non-Python code (I/O, say: that gives its own issues), or are you doing something else than running in a pristine install without the tweaks the docs describe to only pause some of the threads...?
Upvotes: 1