python 多进程获取返回值

2022-01-09 09:19:56 浏览数 (1)

1 def worker(procnum, return_dict): '''worker function''' print str(procnum) ' represent!' return_dict[procnum] = procnum

if name == 'main': manager = Manager() return_dict = manager.dict() jobs = [] for i in range(5): p = multiprocessing.Process(target=worker, args=(i,return_dict)) jobs.append(p) p.start()

代码语言:javascript复制
for proc in jobs:
    proc.join()
print return_dict.values()

2 p = multiprocessing.Pool(1) rslt = p.map(test,('world',)) print rslt

0 人点赞