Why does producer delay halt shell pipe?

D

dwhall

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
 
N

Nanjundi

filters. Is there any way to write the filter to make this work?

thanks,

!!Dean

turn off python buffering & it should work.
export PYTHONUNBUFFERED=t

n'joy
-N
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top