run different functions in parallel

Solutions on MaxInterview for run different functions in parallel by the best coders in the world

showing results for - "run different functions in parallel"
Leni
18 Feb 2018
1#!/usr/bin/env python3
2def task_a():
3    print('this is task a')
4def task_b():
5    print('this is task b')
6def hello(msg):
7    print('Hello: %s'%(msg))
8
9def run_parallel(*functions):    
10  '''    Run functions in parallel    '''    
11  from multiprocessing import Process    
12  processes = []    
13  for function in functions:        
14    proc = Process(target=function)        
15    proc.start()        
16    processes.append(proc)    
17  for proc in processes:        
18    proc.join()
19    
20if __name__ == '__main__':
21    run_parallel(task_a(),task_b(),hello(msg="konstantinos"))