Delays getting data on sys.stdin.readline() ?
Steve Holden
steve at holdenweb.com
Sat Nov 19 23:36:30 EST 2005
Christian Convey wrote:
> Hello,
>
> I've got a program that (ideally) perpetually monitors sys.stdin for
> lines of text. As soon as a line comes in, my program takes some
> action.
>
> The problem is, it seems like a very large amount of data must
> accumulate on sys.stdin before even my first invocation of readline()
> returns. This delay prevents my program from being responsive in the
> way it must be.
>
> Has anyone else seen this effect? If so, is there a reasonable workaround?
>
Generally speaking there will be buffering of the output process that's
feeding your standard input. You can try to set sys.stdin to be
unbuffered (look at the interpreter's -u option), but depending on how
the feeding process is organized it might hold data in its buffers
before it appears on your process's stdin.
You may have noticed the same thing in Unix-like operating systems when
running tail -f on a file being fed by an active process: the output
appears in chunks ending in partial lines because the feeding process's
output buffer has been filled and the operating system has passed it to
the tail process.
regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006 www.python.org/pycon/
More information about the Python-list
mailing list