您需要使用
multiprocessing.Manager.list:
from multiprocessing import Process, Managerdef dothing(L, i): # the managed list `L` passed explicitly. L.append("anything")if __name__ == "__main__": with Manager() as manager: L = manager.list() # <-- can be shared between processes. processes = [] for i in range(5): p = Process(target=dothing, args=(L,i)) # Passing the list p.start() processes.append(p) for p in processes: p.join() print L
请参阅在进程之间共享状态。( 服务器进程 部分)。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)