process.start() method

The process.start() method in Python executes the process using the contents of the run() function or the callable object passed to the target parameter of the Process constructor. Python examples of both the cases are provided along with output.

Process Updated 3 Feb 2019 1 min read

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

python
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

Output
Parent Process started

Message added by the child process

Parent Process exiting

Example 2

python
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

Output
Message added by the child process