Python多進(jìn)程(multiprocessing)共享變量
#!/usr/bin/env python2
# coding: utf8
import multiprocessing
def foo(h,context):
if h%2 == 0:
print (h)
else:
context.append(h)
if __name__ == "__main__":
## 設(shè)置共享list
con = multiprocessing.Manager().list()
## 設(shè)置進(jìn)程池大小
p = multiprocessing.Pool(2)
for i in range(18):
# con = multiprocessing.Manager().list()
p.apply_async(foo,args=(i,con))
p.close()
p.join()
print con
分享標(biāo)題:Python多進(jìn)程(multiprocessing)共享變量
網(wǎng)站鏈接:
http://weahome.cn/article/gpshge.html