简体   繁体   English

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

[英]How to pause main thread untill finishes the execution of set of parallel threads?

First of all I am new to the python multithreading. 首先,我是python多线程的新手。 I have a program that detect hands of set of photos using multiple parallel threads and after detecting main program do some functions based on that hand detected images. 我有一个程序,使用多个并行线程检测一组照片的手,并在检测到主程序后,根据手检测到的图像执行一些功能。 functions are on main thread. 函数在主线程上。 But now both functions and hand detection threads are running parallel. 但现在功能和手检测线程都是并行运行的。 I need to pause main thread until finishes the execution of hand detection threads.Sorry for my language mistakes. 我需要暂停主线程直到完成手检测线程的执行。我的语言错误。

#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()
............



As you maintain the list threads already, you can just call join on all of its elements: 在您维护列表threads ,您可以在其所有元素上调用join

for thread in threads:
  thread.join()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 python3中,子线程满足某些条件时如何暂停和唤醒主线程? - In python3, how to pause and wake up the main thread when some conditions are satisfied by child threads? Python暂停线程执行 - Python pause thread execution 暂停Python中的主线程 - Pause main thread in Python 如果任何其他线程在 Python 中观察到异常,则立即停止主线程执行 - Stop main thread execution immediately if any of the other threads observes an exception in Python ThreadingTcpServer和线程:如何从主线程关闭服务器? - ThreadingTcpServer and Threads: how to shutdown the server from the main thread? 如何从Python中的主线程终止Producer-Consumer线程? - How to terminate Producer-Consumer threads from main thread in Python? 如何阻塞主线程直到所有其他线程完成执行? - How to block the main thread until all the other threads finish executing? 当 Python 并发未来对象完成时,如何停止主线程而不进行轮询? - How does one stop the main thread when a Python concurrent future object finishes, without polling? 启动后如何使主线程等待内部线程? - How to make the main thread wait for the internal threads after starting them? 主线程退出后如何保持守护进程线程存活? - How to keep the daemon threads alive after main thread exits?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM