我正在使用Wing IDE调试多线程Python程序。
当我按下暂停按钮时,它只会暂停一个线程。我已经尝试了十次它总是暂停相同的线程,在我的情况下称为“ThreadTimer线程”,而其他线程继续运行。我想暂停这些其他线程,以便我可以继续使用它们。我该怎么做?
答案 0 :(得分:1)
我不知道Wing IDE是否可以进行多线程调试。
但是您可能对具有此功能的Winpdb感兴趣
答案 1 :(得分:1)
每个the docs,所有运行Python代码的线程都会被停止(默认情况下,即除非您不再想要达到不同的效果)。您看到的线程是否没有停止运行非Python代码(I / O,比如:它给出了自己的问题),或者您正在做的其他事情而不是在原始安装中运行而没有调整文档所描述的仅停顿一些线程......?
答案 2 :(得分:0)
我只是在创建线程时命名它们。
示例线程:
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()
这样你就可以随时从线程内部访问名称
print(threading.currentThread())
sys.stdout.flush() #this is essential to print before the thread is completed
您还可以列出具有特定名称的所有线程
for at in threading.enumerate():
if at.getName().split(' ')[0] == 'Connection':
print('\t'+at.getName())
可以对进程执行类似的操作。
示例流程:
import multiprocessing
process1 = multiprocessing.Process(target=function,
name='ListenerProcess',
args=(queue, connections, known_clients, readouts),
daemon=True)
process1.start()
使用进程会更好,因为您可以从外部通过其名称终止特定进程
for child in multiprocessing.active_children():
if child.name == 'ListenerProcess':
print('Terminating:', child, 'PID:', child.pid)
child.terminate()
child.join()