为什么我不能在Windows上的multiprocessing.Connection对象上轮询()? [英] Why cannot I poll() on a multiprocessing.Connection object on Windows?

查看:92
本文介绍了为什么我不能在Windows上的multiprocessing.Connection对象上轮询()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 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 polls 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方法与底层句柄(recvsend)交互作用

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 Clients constructor.

这篇关于为什么我不能在Windows上的multiprocessing.Connection对象上轮询()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆