Python - Fork Modules
Question: My requirement is to do something like below -

    
    
    def task_a():
    ...
    ...
    ret a1
    
    def task_b():
    ...
    ...
    ret b1
    
    .
    .
    
    def task_z():
    ...
    ...
    ret z1
    

Now in my main code I want to Execute Tasks a..z in parallel and then wait for
the return values of all of the above..

    
    
    a = task_a()
    b = task_b()
    z = task_z()
    

Is there a way to call the above modules in parallel in Python?

Thanks, Manish


Answer: > Reference: [Python: How can I run python functions in
> parallel?](http://stackoverflow.com/questions/7207309/python-how-can-i-run-
> python-functions-in-parallel)

Import:

    
    
    from multiprocessing import Process
    

Add new function:

    
    
    def runInParallel(*fns):
      proc = []
      for fn in fns:
        p = Process(target=fn)
        p.start()
        proc.append(p)
      for p in proc:
        p.join()
    

Input existing functions into the new function:

    
    
    runInParallel(task_a, task_b, task_c...task_z)
    

