First of all I am new to the python multithreading. 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()
............



1 Answers

0
tevemadar On

As you maintain the list threads already, you can just call join on all of its elements:

for thread in threads:
  thread.join()