0

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

myloginid
  • 1,463
  • 2
  • 22
  • 37
  • Where have you looked for answers so far? I tried searching for `python run in parallel` and saw a bunch of useful looking results. – larsks Mar 18 '15 at 13:28

1 Answers1

1

Reference: 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)
Community
  • 1
  • 1
logic
  • 1,739
  • 3
  • 16
  • 22