代码:
from threading import Thread
import time
def main():
print([threadID])
time.sleep(5)
pass
if __name__ == '__main__':
threadID = 0
while threadID < 5:
main()
threadID +=1
当前,它运行第一个线程,然后一旦完成,就开始下一个线程。
如何使所有线程同时启动?
答案 0 :(得分:0)
我觉得有点愚蠢,但从未真正调用过线程...
代码:
from threading import Thread
import time
def main():
print([threadID])
time.sleep(5)
pass
if __name__ == '__main__':
threadID = 0
while threadID < 5:
t = Thread(target=main)
t.start()
threadID +=1