Method Name:
join
Method Signature:
join()
Return Value:
NoneType
Parameters:
Not Applicable
Method Overview:
- Calling join() on a Process instance makes the calling process to wait for the corresponding process.
- Once the process is complete the called process proceeds.
- In the examples provided on multiprocessing it is the main process that calls the join() method on the Process instances corresponding the child processes.
- Calling join() on the Process instance for the same process results in deadlock.
- join() can be called only on an already started process.
- join() is similar to a person waiting for another person to complete something and proceeding after it.
Example:
import multiprocessing as multiproc def processCategory1(mq): def processCategory2(mq): def processCategory3(mq): if __name__=="__main__": mq = multiproc.Queue() # Create child processes # Start all the child processes print("Child processes started....main process waiting for children to complete") # Wait for all the child processes to complete print("Child processes completed execution") while mq.empty() is False: print("Parent process ending") |
Output:
Parent process started Child processes started....main process waiting for children to complete Child processes completed execution Category1 message Category2 message Category3 message Parent process ending |