I thought each processes pipe connected work asynchronously but it doesn't.
a.py
#!/usr/bin/env python
import sys
import time
for line in sys.stdin:
time.sleep(2)
sys.stdout.write(line.upper())
sys.stdout.flush()
and b.py
#!/usr/bin/env python
import sys
for line in sys.stdin:
sys.stdout.write(line.capitalize())
sys.stdout.flush()
and test.txt
hello
world
python
Following code show each lines one by one by 2 seconds.
$ ./a.py < test.txt
HELLO
WORLD
PYTHON
But following code show entirely one time.
$ ./a.py < test.txt | ./b.py
Hello
World
Python
It looks that shell pipe is working synchronously. How can I do asynchronously?