from multiprocessing import Process, Pipe
def sender(pipe):
pipe.send(['spam'] + [42, 'eggs']) # pipe.send() で書き込み
pipe.close()
def talker(pipe):
pipe.send(dict(name='Bob', spam=42))
reply = pipe.recv() # pipe.recv() で読み込み
print('talker got', reply)
if __name__=='__main__':
parentEnd, childEnd = Pipe() # パイプを作成
Process(target=sender, args=(childEnd,)).start() # プロセスを始める
print('parent got:', parentEnd.recv())
parentEnd.close()
parentEnd, childEnd = Pipe()
child = Process(target=talker, args=(childEnd,))
child.start()
print('parent got:', parentEnd.recv())
parentEnd.send({x * 2 for x in 'spam'})
child.join()
print 'parent exit'
0 件のコメント:
コメントを投稿