我有對象將多個管道(雙向)。我需要的是等到任何這些管道中出現任何物體。不幸的是,當我嘗試做這樣的事情:選擇多個管道
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上這些文件描述符可能無法正常工作,但我不確定。現在我明白了。謝謝!