Non-blocking pipe read under Windows NT

Noah Noah at noah.org
Thu Feb 22 03:27:02 EST 2001


Hmmm... Windows Python2.0 does not have fcntl.
How do I do a non-blocking select on a Pipe file descriptor?

Under UNIX I can do something like this:

# hard way to read a file

import os, fcntl, FCNTL

# Open a pipe to read a file.
(fin, fout, ferr) = os.popen3 ('cat testfile')

# Turn off blocking on file. read() will then return -1 if no data
flags = fcntl.fcntl (fout.fileno(), FCNTL.F_GETFL, 0)
flags = flags | FCNTL.O_NONBLOCK
fcntl.fcntl (fout.fileno(), FCNTL.F_SETFL, flags)

# Print out the file without blocking.
done = 0
while !done:
    (r,w,e) = select.select ([fout], [], [], None)
    if len(r) > 0:
        data = r[0].read()
        if data == -1:
            done = 1
        else:
            print data





More information about the Python-list mailing list