Method Name:
start
Method Signature:
start()
Return Value:
NoneType
Method Overview:
- Calling start() method results in executing the process using the run method.
- In case when run is empty the target parameter provided through the Process constructor will be used.
- On a given Process instance start() method should be invoked only once.
Parameters:
Not Applicable
Example 1:
import multiprocessing as multiproc
class CustomProcess(multiproc.context.Process): def __init__(self, mq): multiproc.Process.__init__(self) self.mq = mq
# Override run def run(self): self.mq.put("Message added by the child process")
if __name__=='__main__': print("Parent Process started") multiproc.set_start_method('spawn') mq = multiproc.Queue()
childProcess = CustomProcess(mq) childProcess.start() childProcess.join()
print(mq.get()) print("Parent Process exiting") |
Output:
Parent Process started Message added by the child process Parent Process exiting |
Example 2:
import multiprocessing as multiproc def processInst(mq): mq.put("Message added by the child process") if __name__=='__main__': multiproc.set_start_method('forkserver') mq = multiproc.Queue() childProcess = multiproc.Process(target=processInst, args=(mq,)) childProcess.start() childProcess.join()
print(mq.get()) |
Output:
Message added by the child process |