我有对象将多个管道(双向)。我需要的是等到任何这些管道中出现任何物体。不幸的是,当我尝试做这样的事情:选择多个管道
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需要ints(文件描述符)或带有无参数函数fileno()的对象(使用Pipe()创建的Connection对象已获得)。我甚至试过:
w, r = os.pipe()
read, _, _ = select.select([w, r], [], [])
但错误是一样的。任何ideads?
编辑
是的,我目前在Windows上工作,但它看起来像我将不得不改变平台...感谢您的答案。我有这种想法,在Windows上这些文件描述符可能无法正常工作,但我不确定。现在我明白了。谢谢!