【发布时间】:2014-01-24 00:42:17
【问题描述】:
我有多个管道(双向)。我需要的是等到这些管道中的任何一个出现任何对象。不幸的是,当我尝试做这样的事情时:
from multiprocess import Pipe
import select
class MyClass:
def __init__(self, pipe1, pipe2):
self.__my_pipes = [pipe1, pipe2]
def run(self):
while 1:
ready, _, _ = select.select(self.__my_pipes, [], [])
#and some stuff
我遇到了错误
OSError: [WinError 10038] an operation was attempted on something that is not a socket
MyClass 的构造函数是这样调用的:
pipe1, pipe2 = Pipe()
pipe3, pipe4 = Pipe()
obj = MyClass(pipe1, pipe3)
根据文档,select.select 需要整数(文件描述符)或具有无参数函数 fileno() 的对象(使用 Pipe() 创建的 Connection 对象具有)。我什至尝试过这样做:
w, r = os.pipe()
read, _, _ = select.select([w, r], [], [])
但错误是一样的。有什么想法吗?
编辑
是的,目前我正在使用 Windows,但看起来我必须更改平台...感谢您的回答。我有这样的想法,在 Windows 上,这些文件描述符可能不起作用,但我不确定。现在我明白了。谢谢!
【问题讨论】:
标签: python python-3.x multiprocessing pipe