In Jython, it doesn't seem be possible to flush the buffer of a
'write'-mode pipe on request the way Python does (pipe.flush() has no
effect).
At bottom is a simple program to create a pipe, write to it, read from
it, and close. The behavior in Python is as expected:
$ python post.py
Read this line from child: "Read this line from parent: 'Test line'"
Waiting 10 seconds
Exiting
In Jython, though, the program hangs until quit forcibly:
$ jython post.py
Traceback (most recent call last):
File "/usr/local/sem/CampaignManager/src/test/Pipes/post.py", line 6, in ?
line = sys.stdin.readline()[:-1]
KeyboardInterrupt
If I close the pipe, instead of just flushing, though, the behavior is
correct, which leads me to think that 'flush()' is being ignored. This
is important for being able to use pipes.
Cheers,
Danny
import os
import sys
import time
if len(sys.argv) > 1: # Child
line = sys.stdin.readline()[:-1]
sys.stdout.write("Read this line from parent: '%s'" %line)
sys.stdout.flush()
else:
pin,pout = os.popen2('/usr/bin/jython
/usr/local/sem/CampaignManager/src/test/Pipes/post.py --child')
pin.write("Test line\n")
pin.flush()
#pin.close()
print 'Read this line from child: "%s"' %pout.readline()
print "Waiting 10 seconds"
time.sleep(10)
print "Exiting"