Why does producer delay halt shell pipe?

dwhall dwhall256 at gmail.com
Tue Dec 11 13:05:42 EST 2007


I have 2 python scripts: examples of a producer and a filter,
respectively:

    #! /usr/bin/env python
    import sys, time
    if __name__ == "__main__":
        while True:
            sys.stdout.write("hello.\r\n")
            time.sleep(0.000001)

    #! /usr/bin/env python
    import sys
    if __name__ == "__main__":
        line = sys.stdin.readline()
        while line:
            sys.stdout.write(line.upper())
            line = sys.stdin.readline()

I wish to use these programs in Bash, like so:

    $ ./producer.py | ./filter.py

However, the producer's time delay makes this not work.  If I remove
or reduce the delay, it works.  In reality the producer has an
unavoidable one-second delay.  I do NOT want to use popen or its
cousins because I want flexibility from the command line; I have many
filters.  Is there any way to write the filter to make this work?

thanks,

!!Dean



More information about the Python-list mailing list