win32: emulating select() on pipes

gangesmaster tomerfiliba at
Mon Mar 17 21:52:32 CET 2008


i'm trying to figure out if a pipe on win32 has data for me to read.
this is the code i've come up with:

        def poll(self, timeout, interval = 0.2):
            """a poor man's version of select() on win32"""
            from win32pipe import PeekNamedPipe
            from msvcrt import get_osfhandle

            handle = get_osfhandle(self.fileno())
            if timeout is None:
                timeout = sys.maxint
            length = 0
            tmax = time.time() + timeout
            while length == 0 and time.time() < tmax:
                length = PeekNamedPipe(handle, 0)[2]
            return length != 0

does anyone know of a better way to tell if data is available on a
something that blocks until data is available or the timeout is
and returns True if there's something for me to read, or False


More information about the Python-list mailing list