I have been stuck on this problem for almost an hour and couldn't find a solution or a work around.
Here is my problem:
I have a subprocess that starts a subscriber S that listens to some real time data publisher P. P randomly publish data at a random time, and I want to get all the data within a timespan (say 30 seconds).
subscriber = subprocess.Popen('/start/process', stdout = PIPE, stderr = PIPE)
max_time = 30
inital_time = time.time()
while time.time()-initial_time < max_time:
try:
print(subscriber.stdout.readline())
except:
pass
After compiling, I find the while loop blocked by the readline() when P doesn't publish data. The loop stops at the print until P publish some data, and then the loop prints the data and go to the condition check. So if P never publish data, the program never ends.
I'm assuming that this is because readline require some sort of input in order for it to return, so my questions is how to I work around this? I have read this and I don't see anything related.