标签:pytho python2 lse pre code context env ssi name
Python多进程(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__":
## 设置共享list
con = multiprocessing.Manager().list()
## 设置进程池大小
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
Python多进程(multiprocessing)共享变量
标签:pytho python2 lse pre code context env ssi name
原文地址:https://blog.51cto.com/11114389/2438052