如何暂停主线程,直到完成并行线程集的执行?

时间:2019-05-12 14:48:58

标签: python multithreading

首先,我是python多线程的新手。我有一个程序可以使用多个并行线程来检测一组照片的手,并且在检测到主程序后,会根据该手检测到的图像执行一些功能。函数在主线程上。但是现在函数和手检测线程都正在并行运行。我需要暂停主线程,直到完成手部检测线程的执行。抱歉我的语言错误。

#Thread creation function

def callThreads(self, imageLst):
        global taskLock, tasks
        for tid in range(1, 10, 1):  ## 1,11,1
            thread = handdetect.detectHandThread(imageLst, tid, 'thread_{}'.format(tid), tasks, taskLock,
                                                 obj_detection_graph_queue, obj_detLock)
            thread.start()
            threads.append(thread)
            print("[INFO] Thread {} created and added to the pool...".format(tid))
# main() function of the programme
..............
self.callThreads(filenames)

Some functions()
............



1 个答案:

答案 0 :(得分:0)

在您已经维护列表threads时,只需调用其所有元素上的join

for thread in threads:
  thread.join()