Blood Blood - 8 months ago 74
Python Question

Select on multiple pipes

I have object will multiple pipes (bidirectional). What i need is to wait until in any of these pipes any objects show up. Unfortunately, when i try to do something like this:

from multiprocess import Pipe
import select

class MyClass:
def __init__(self, pipe1, pipe2):
self.__my_pipes = [pipe1, pipe2]

def run(self):
while 1:
ready, _, _ =, [], [])
#and some stuff

I'm getting error

OSError: [WinError 10038] an operation was attempted on something that is not a socket

Constructor of MyClass is invoked like this:

pipe1, pipe2 = Pipe()
pipe3, pipe4 = Pipe()
obj = MyClass(pipe1, pipe3)

According to documentation, requires ints (file descriptors) or objects with parameterless function fileno() (which Connection objects created with Pipe() have got). I have even tried to do:

w, r = os.pipe()
read, _, _ =[w, r], [], [])

but error was the same. Any ideads?


Yes, currently i'm working on Windows, but it looks like i'll have to change platform ... Thanks for answers. I have this thoughts that on Windows those file descirptors might not work, but i wasn't sure. Now i know. Thanks!


You are calling select() with an array containing Connection objects as used by multiprocessing. (Btw, you were writing multiprocess in your source, but I guess it should be multiprocessing.) select(), however, cannot handle these.

Try using pipe1.fileno() etc. instead; this is a file number (an int) and select is perfectly capable of working with these.


If you are working on windows, file numbers are not supported by select() (bad luck). I cannot help then. Unless you would be willing to go multithreading and have one thread for each thing to wait on; that should also work on Windows.