Hi,

On Mar 1, 2005, at 6:01 PM, Sean Perry wrote:

[EMAIL PROTECTED] wrote:
If I do:
$ ./produce.py | ./read.py
I get nothing for ten seconds, then I get the numbers 0 through 9, one per line.
What am I missing?

From the python man page:
-u
Force stdin, stdout and stderr to be totally unbuffered. On systems where it matters, also put stdin, stdout and stderr in binary mode. Note that there is internal buffering in xreadlines(), readlines() and file-object iterators ("for line in sys.stdin") which is not influenced by this option. To work around this, you will want to use "sys.stdin.readline()" inside a "while 1:" loop.



What exactly is the "right" way to put sys.stdin in unbuffered mode?

in another program I've tried to accomplish that by doing something like this

import os
import fcntl

<...>

stdinfd = sys.stdin.fileno()
fcntl.fcntl(stdinfd, fcntl.F_SETFL, os.O_NONBLOCK)

...

and then calling  later

data = sys.stdin.read(numbytes)

is this correct?

-Pete

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to