为什么我不能在Windows上的multiprocessing.Connection对象上轮询()? [英] Why cannot I poll() on a multiprocessing.Connection object on Windows?
问题描述
使用 multiprocessing.Pipe 我创建了两个 multiprocessing.Connection 对象,其中一个我读取了文件描述符/句柄通过Conection.fileno()
,然后将其作为命令行参数传递给另一个进程.我相信这类似于多处理产生子进程的方式.
Using multiprocessing.Pipe I create two multiprocessing.Connection objects, for one of which I read the file descriptor/handle through Conection.fileno()
and then pass it as a command line argument to another process. I believe this is similar to how multiprocessing spawns child-processes.
在子进程中,我正在创建 multiprocessing.Connection 对象,方法是从命令行参数读取句柄,然后在两个进程之间进行通信.
In a child process, I'm creating a multiprocessing.Connection object by reading the handle from a command line argument, and then communicate between two processes.
这在我的Mac上运行良好,但是由于某些原因在Windows上调用Connection.poll
方法会导致以下错误:
This works well on my mac but for some reason calling the Connection.poll
method on windows results in the following error:
IOError:[Errno 10038]尝试对非套接字的东西进行操作
IOError: [Errno 10038] An operation was attempted on something that is not a socket
造成差异的原因是什么?为什么在poll
的文档中没有提及?
What is the cause of the difference? Why there's no mention of that in poll
s documentation?
一个简单的代码示例可能类似于:
A simple code example could be something like:
在father.py中:
In father.py:
c1, c2 = multiprocessing.Pipe()
subprocess.Popen(['child.py', str(c1.fileno())])
在child.py中:
In child.py:
c1 = multiprocessing.Connection(int(sys.argv[1]))
c1.poll(1)
有关其他详细信息,请此问题与解答进行描述我想要实现的目标以及最终实现的目标.
For additional details, this question and answer of mine describe what I'm trying to achieve and how I ended up doing that.
推荐答案
原来,问题并非特定于poll
,而是所有Connection
方法与底层句柄(recv
,send
)交互作用
Turns out the issue was not specific to poll
, but with all Connection
methods interacting with the underlaying handle (recv
, send
).
因为multiprocessing.Pipe
在Windows中创建了一个命名管道,并结合了python2中管道句柄继承的工作方式(曾经被确定为显示为漂亮 重传)手柄似乎很困难,即使不是不可能.
Because multiprocessing.Pipe
creates a named pipe in windows, combined with how pipe handle inheritance works in python2 (which once identified as the root cause shown to be discussed pretty heavily) passing on an handle seems to be very difficult if not impossible.
再次浏览多处理的文档,我注意到 Client
接口Listener.address
属性中的所有内容传递给Client
的构造方法.
Going over multiprocessing's documentation again, I noticed the Listener
and Client
interfaces which worked well for me, passing along whatever was in the Listener.address
attribute to Client
s constructor.
这篇关于为什么我不能在Windows上的multiprocessing.Connection对象上轮询()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!