My problem is somewhat similar to this question.
I try to communicate from Python with a Jython program (that needs to keep running because it communicates with a Java API).
However, i can't get the output in realtime, whatever i try:
p2=Popen([path_jython],stdin=PIPE, stdout=PIPE, stderr=PIPE, shell=False)
p2.stdin.write('test="hallo"\n')
p2.stdin.write('print test\n')
p2.stdin.flush()
for line in p2.stdout:
print line
Nothing happens, the program blocks. It doesn't change when i iterate over p2.stdout.readlines() or iter(md5.stdout.readline, '') or when I repeatedly call p2.stdout.read(1) like suggested in the linked question.
If i add print p2.communicate() after the flush() however, i get the desired output:
>>> ('hallo\r\n', '\r\n')
but the program terminates afterwards...
Does anyone have a solution for this problem? Or are there alternatives to communicate effectively with a running Jython process? Happy for any advice!
EDIT: Python 2.7.5, Jython 2.7.1b