Following code not executing as expected.
import multiprocessing
lock = multiprocessing.Lock()
def dummy():
def log_results_l1(results):
lock.acquire()
print("Writing results", results)
lock.release()
def mp_execute_instance_l1(cmd):
print(cmd)
return cmd
cmds = [x for x in range(10)]
pool = multiprocessing.Pool(processes=8)
for c in cmds:
pool.apply_async(mp_execute_instance_l1, args=(c, ), callback=log_results_l1)
pool.close()
pool.join()
print("done")
dummy()
But it does work if the functions are not nested. What is going on.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…