Something new from me:
I have an application which can act as server and client (launch them on separate PCs). I need the server stdout because it displays some data for evaluating their communication. I start the server through a subprocess.Popen giving its stdout to PIPE
from subprocess import Popen,PIPE import os #Start subprocess cmd = 'myAppli arg1 arg2 arg3' p = Popen(cmd,shell=True,stdin=PIPE,stdout=PIPE) #I know when the client is done sending and I kill p if ClientDoneCondition: os.system('TASKKILL /PID '+str(p.pid)+' /F') #The only way I found to kill subprocesses #Now I can analyse stdout, line by line preferably line = p.stdout.readline() while line.find("what want") == -1: line = p.stdout.readline() print 'Final line', line
The fact is that I know normally what part of the final line never changes so I can identify it, because readline() blocks if I try to read stuff after all the writing is done because the appli-server never closes and the forced kill doesn't put EOF at the end of stdout.
The problem is that the server can lose connection or stuff might happen which doesn't allow to get to the last line where my condition can be met, so , what I'm trying to ask:
- Is there another way except readline() to go through stdout and not block readline() due to lack of EOF
I would recover all the existing lines and conclude my analysis from the info they contain, ...
NOte: I tried putting a thread, but since they can't be kille din Python and even if timed out, the readline inside blocks, I get nowhere...