Python - 分叉模块
Python - Fork Modules
我的要求是执行如下操作 -
def task_a():
...
...
ret a1
def task_b():
...
...
ret b1
.
.
def task_z():
...
...
ret z1
现在在我的主要代码中,我想并行执行任务 a..z,然后等待上述所有任务的 return 值..
a = task_a()
b = task_b()
z = task_z()
有没有办法在Python中并行调用上述模块?
谢谢,
马尼什
Reference:
Python: How can I run python functions in parallel?
导入:
from multiprocessing import Process
添加新功能:
def runInParallel(*fns):
proc = []
for fn in fns:
p = Process(target=fn)
p.start()
proc.append(p)
for p in proc:
p.join()
将现有函数输入新函数:
runInParallel(task_a, task_b, task_c...task_z)
我的要求是执行如下操作 -
def task_a():
...
...
ret a1
def task_b():
...
...
ret b1
.
.
def task_z():
...
...
ret z1
现在在我的主要代码中,我想并行执行任务 a..z,然后等待上述所有任务的 return 值..
a = task_a()
b = task_b()
z = task_z()
有没有办法在Python中并行调用上述模块?
谢谢, 马尼什
Reference: Python: How can I run python functions in parallel?
导入:
from multiprocessing import Process
添加新功能:
def runInParallel(*fns):
proc = []
for fn in fns:
p = Process(target=fn)
p.start()
proc.append(p)
for p in proc:
p.join()
将现有函数输入新函数:
runInParallel(task_a, task_b, task_c...task_z)