Windows上使用python的多处理管道 [英] Multiprocessing pipes on windows with python
本文介绍了Windows上使用python的多处理管道的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Windows是否支持multithreading.pipes()?如果是,那么此代码有什么问题?我需要使用减少量吗?代码挂在p2.recv()上,从命令行运行时出现RuntimeError.
Does Windows support multithreading.pipes()? If yes, then what is wrong with this code? Do I need to be using reduction? The code hangs on p2.recv() and I get a RuntimeError when run from the command line.
import multiprocessing
def ProcessCreator(pipe):
pipe.send("hello from other process")
p1, p2 = multiprocessing.Pipe()
proc = multiprocessing.Process(target = ProcessCreator, args = (p2,))
proc.start()
print p1.recv()
if __name__ == "__main__":
multiprocessing.freeze_support()
推荐答案
如果__name__ =='__main __'部分,则需要将管道代码放入.(
You need put pipe code into if __name__ == '__main__' part.(Why?) And change p2.recv to p1.recv
import multiprocessing
def ProcessCreator(pipe):
pipe.send("hello from other process")
if __name__ == "__main__":
multiprocessing.freeze_support()
p1, p2 = multiprocessing.Pipe()
proc = multiprocessing.Process(target = ProcessCreator, args = (p2,))
proc.start()
print p1.recv()
这篇关于Windows上使用python的多处理管道的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文