标签:
Python中进程间共享数据,除了基本的queue,pipe和value+array外,还提供了更高层次的封装。使用multiprocessing.Manager可以简单地使用这些高级接口。
Manager支持的类型有list,dict,Namespace,Lock,RLock,Semaphore,BoundedSemaphore,Condition,Event,Queue,Value和Array。
import time import multiprocessing def worker(d, key, value): d[key] = value if __name__ == ‘__main__‘: print time.strftime(‘%y-%m-%d %H:%M:%S‘ , time.localtime()) mgr = multiprocessing.Manager() d = mgr.dict() jobs = [ multiprocessing.Process(target=worker, args=(d, i, i*2)) for i in range(10) ] for j in jobs: j.start() for j in jobs: j.join() print (‘Results:‘ ) for key in dict(d): print "%s->%s" % (key,d[key])
转自:http://www.cnblogs.com/itech/archive/2012/01/10/2318120.html
标签:
原文地址:http://www.cnblogs.com/codeAB/p/4229087.html