stdio EOF ?

Joshua Schmidlkofer menion at asylumwear.com
Mon Aug 12 01:52:29 EDT 2002


On Sun, 2002-08-11 at 14:39, Steve Holden wrote:
> "Jacek Generowicz" <jacek.generowicz at cern.ch> wrote in message
> news:tyfr8h883my.fsf at pcitapi22.cern.ch...
> > I'm trying to write a filter (between the GNU plotutils ode and
> > graph). The problem I have is making it work in a situation like this:
> >
> >   cat | filter.py | whatever
> >
> >  (ode -f foo | filter.py | graph ... in reality)
> >
> > The desired behaviour is that I should be able to type instructions
> > into standard input (which ode reacts to, sending data down the
> > pipeline) which the filter should process and pass on down the
> > pipeline without waiting ... but should stop when I send EOF.
> >
> > Using "for line is stdin: ..." works if all the commands are in a file
> > and I do
> >
> >   cat command_file | filter.py | etc
> >
> > but in the "cat | filter.py" situation, it doesn't produce any output
> > until C-d is sent.
> >
> > I guess I'm looking for a "while something(stdin)" or "while
> > stdin.something" construct ...
> >
> > Any ideas ?
> >
> 
> Probably the most significant thing you can do is run the interpreter with
> the -u (unbuffered) option, to try to ensure that I/O transmission will be
> as immediate as possible. When you are feeding a pipeline it's often
> difficult to ensure that the input to the downstream process is delivered
> exactly when you want it to be (because of buffering). Judicious use of
> f.flush() can be helpful.
> 
> regards
> -----------------------------------------------------------------------
> Steve Holden                                 http://www.holdenweb.com/
> Python Web Programming                http://pydish.holdenweb.com/pwp/
> -----------------------------------------------------------------------
> 

Perhaps someone should implement a suck() method for programs which are
thwarted by being down stream of someone who doesn't know when to
flush().

js







More information about the Python-list mailing list