现在,我有以下函数test()
def test():
f1(par) # extremely time consuming
f2() # f2 must be executed after f1()
f1()在时间上非常昂贵。 f2()必须在f1()之后执行。 我想使用多重处理来加速f1(),所以我修改了test():
import multiprocessing as mp
from multiprocessing import Pool
def test():
pool = Pool(processes=mp.cpu_count())
res = [pool.apply_async(f1, (p)) for p in list_pars]
#
# ??? pause or what?
#
f2() # f2 must be executed after f1()
f1()加快了速度,但是在f1()完成之前执行了f2()。 如何让程序稍等一下?在完成f1()之后,它将开始执行f2()。我应该如何修改密码?
谢谢。