win32: emulating select() on pipes

gangesmaster tomerfiliba at gmail.com
Mon Mar 17 16:52:32 EDT 2008


hi

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]
                time.sleep(interval)
            return length != 0

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


-tomer



More information about the Python-list mailing list