1

I have multiple independent python scripts which I want to run parallelly. I am trying to achieve this through Multiprocessing library. I tried below code but its keep on running and there is no output.

import os
from multiprocessing import Pool

processes = ['1.py','2.py','3.py']

def run_processes (process):
    os.system('python {}'.format(process))

if __name__ == "__main__":
    pool = Pool (processes=3)
    pool.map(run_processes, processes)

Please advise where am I wrong here.

Mohit Garg
  • 61
  • 5

1 Answers1

0

You need to use:

if __name__ == "__main__":

like it says in the first paragraph of the documentation on multiprocessing.

Mark Setchell
  • 191,897
  • 31
  • 273
  • 432