【发布时间】:2019-02-14 00:18:54
【问题描述】:
我们正在开发一个具有多个线程的 Python 2.7 程序。我们还创建了一个线程来监督所有线程是否正常运行。本质上就是这么简单:
all_my_threads = [controlador, usb, telegram, watch, registro, pantalla, hilo1, auto, authentication]
while True:
for thread in all_my_threads:
if (thread.isAlive()):
print (str(thread) + " is alived.")
else:
print (str(thread) + " is not alived.")
print ("Stating " + str(thread) + " thread.")
thread.start()
time.sleep(15)
当所有线程都在运行时,我们得到:
Thread(Thread-1, started 1943008212) 是存活的。
Thread(Thread-2, started 1943008368) 已存活。
Thread(Thread-3, started 1926231152) 已存活。
Thread(Thread-4, started 1934619760) 已存活。
Thread(Thread-5, started 1961882736) 已存活。
Thread(Thread-6, started 1951396976) 已存活。
Thread(Thread-7, started 1971758192) 已存活。
Thread(Thread-9, started 1982223472) 已存活。
问题是我们已经看到,当一个线程因任何原因中断时,我共享的一段代码会尝试重新启动该线程,但它会因以下错误而崩溃:
线程只能启动一次
所以这段代码肯定有问题……
非常感谢任何想法或建议。
提前致谢;
安德。
【问题讨论】:
标签: python multithreading python-2.7 python-multithreading