标签:
from multiprocessing import Process
def f(name):
print (‘hello‘,name)
if __name__ == ‘__main__‘:
p=Process(target=f,args=(‘freeman‘,))
p.start()
p.join()
from multiprocessing import Process,Value,Array
def f(n,a):
n.value=3.1415972
for i in range(len(a)):
a[i] = -a[i]
if __name__ == ‘__main__‘:
num = Value(‘d‘,0.0)
arr= Array(‘i‘,range(10))
p = Process(target=f,args=(num,arr))
p.start()
p.join()
print (num.value)
print (arr[:])
from multiprocessing import Process,Manager
def f (d,l):
d[1] =‘1‘
d[‘2‘] =2
d[0.25] = None
l.reverse()
if __name__ == ‘__main__‘:
manager=Manager()
d=manager.dict()
l=manager.list(range(10))
p = Process(target=f,args=(d,l))
p.start()
p.join()
print (d)
print (l)
from multiprocessing import Pool
import time
def f(x):
time.sleep(1)
return x*x
if __name__ == ‘__main__‘:
pool = Pool(processes=8)
res_list = []
for i in range(5):
p = pool.apply_async(f,[i])
res_list.append(p)
for i in res_list:
print (i.get())
标签:
原文地址:http://www.cnblogs.com/yjz1/p/5478316.html