I have two Python scripts running on an Ubuntu Linux machine. The 1st one sends all its output into stdout, the second one reads from stdin. They are connected by a simple pipe, i.e. something like this:
./step1.py <some_args> | ./step2.py <some_other_args>
What step2 does is that it reads lines of input in an infinite loop and processes them:
while True:
try:
l = sys.stdin.readline()
# processing here
Step1 crashes from time to time. When that happens (not sure if always but at least on several occasions) is that instead of crashing/stopping, step2 goes crazy and starts taking 100% of the CPU until I manually kill it.
Why is this happening and how can I make step2 more robust so that it stops when the pipe is broken?
Thanks!