qq_遁去的一_1
交换数据一般用queue吧。17.2.1.3. Exchanging objects between processesmultiprocessing supports two types of communicationchannel between processes:QueuesThe Queueclass is a near clone of queue.Queue. For example:from multiprocessing import Process, Queuedef f(q):q.put([42, None, 'hello'])if __name__ == '__main__':q = Queue()p = Process(target=f, args=(q,))p.start()print(q.get()) # prints "[42, None, 'hello']"p.join()Queues are thread and process safe.PipesThe Pipe() function returns a pair of connection objectsconnected by a pipe which by default is duplex (two-way). For example:from multiprocessing import Process, Pipedef f(conn):conn.send([42, None, 'hello'])conn.close()if __name__ == '__main__':parent_conn, child_conn = Pipe()p = Process(target=f, args=(child_conn,))p.start()print(parent_conn.recv()) # prints "[42, None, 'hello']"p.join()The two connection objects returned by Pipe()represent the two ends of the pipe. Each connection object has send()and recv()methods (among others). Note that data in a pipe may become corrupted if twoprocesses (or threads) try to read from or write to the same end of thepipe at the same time. Of course there is no risk of corruption from processesusing different ends of the pipe at the same time.