Non-blocking pipe read under Windows NT
Tom
NoSpam at NoSpam.com
Thu Feb 22 11:52:09 EST 2001
That's a bit tricky.
Windows (at least NT/2K, which fully support named pipes) does support
non-blocking pipes, but I don't think that Python does. But I don't think
that matters. I looked into it a while ago (for C++) and decided that it
would be easier to implement an extra thread than to implement non-blocking
pipes for cross-platform purposes. For one thing, cross-platform threading
libraries are common, whereas non-blocking pipes seem suprisingly uncommon.
So, I don't know what you are trying to do, but if threads are an
alternative soln to your problem (ie. thread + block == non-block), I would
recommend them.
If you still want to persue non-block windows pipes, you could look at the
article "
Named Pipe Type, Read, and Wait Modes" (
http://msdn.microsoft.com/library/psdk/winbase/pipes_60mr.htm). The win32
implementation of Python's thread creation (for the popen fn's) is based on
MS knowledgebase article Q190351 (available from
http://msdn.microsoft.com/library/). These articles are, unfortunately, in
'C'.
Good-luck,
Tom.
"Noah" <Noah at noah.org> wrote in message
news:q34l6.297$0Q5.207467 at news.pacbell.net...
> 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