[Tutor] Sys.stdin Question
John Fouhy
john at fouhy.net
Wed Jan 14 03:05:27 CET 2009
2009/1/14 Damon Timm <damontimm at gmail.com>:
> On Tue, Jan 13, 2009 at 8:55 PM, Steve Willoughby <steve at alchemy.com> wrote:
>> This is playing a dangerous game, though, of introducing a race condition.
>> Is there nothing on the standard input RIGHT NOW because the source on
>> the other end of the pipe hasn't managed to generate anything yet, or
>> because there's nothing piped?
> Does this concern still apply with John's suggestion? I just tested
> it in my little application and didn't have an issue ... of course, I
> only ran a couple different command line items before throwing up my
> hands in celebration.
It's easy to test:
### test.py ###
import time
time.sleep(1)
print 'foo'
###
$ python test.py | python stdintest.py
Nothing to see here.
close failed: [Errno 32] Broken pipe
[not shown: the 1 second pause after "Nothing to see here." showed up]
You could "fix" it by adding a delay to your consumer script.. as long
as none of your input scripts take longer than the delay to generate
output. Or do things differently, which might be smarter :-)
--
John.
More information about the Tutor
mailing list