Launching parallel tasks in Python

PythonServer Side ProgrammingProgramming

If a Python program can be broken into subprograms who is processing do not depend on each other, then each of the subprogram can be run in parallel when the overall program is being run. This concept is known as parallel processing in Python.

With multiprocessing

This module can be used to create many child processes of a main process which can run in parallel. In the below program we initialize a process and then use the run method to run the multiple sub-processes. We can see different sub processes in the print statement by using the process id. We also use the sleep method to see print the statements with a small delay one after another.


 Live Demo

import multiprocessing
import time

class Process(multiprocessing.Process):
   def __init__(self, id):
      super(Process, self).__init__() = id

   def run(self):
      print("Running process id: {}".format(

if __name__ == '__main__':
   p = Process("a")
   p = Process("b")
   p = Process("c")


Running the above code gives us the following result −

Running process id: a
Running process id: b
Running process id: c
Published on 10-Jul-2020 14:44:03