#!/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
原文地址:https://www.cnblogs.com/yes5144/p/11523530.html
时间: 2024-10-07 15:44:11