running python script in parallel

Solutions on MaxInterview for running python script in parallel by the best coders in the world

showing results for - "running python script in parallel"
María Camila
21 Feb 2019
1import multiprocessing
2import os                                                               
3 
4# Creating the tuple of all the processes
5all_processes = ('script_A.py', 'script_B.py', 'script_C.py', 'script_D.py')                                    
6                                                  
7# This block of code enables us to call the script from command line.                                                                                
8def execute(process):                                                             
9    os.system(f'python {process}')                                       
10                                                                                
11                                                                                
12process_pool = multiprocessing.Pool(processes = 4)                                                        
13process_pool.map(execute, all_processes)
14