I am trying to readline
from stdout
of subprocess
. Sometimes device "123" doesn't respond and won't provide and data in stdout
. In that case line out = proc.stdout.readline()
is getting stuck forever. How to come out of loop if there is no response from device.
I am trying to read stdout
of a subprocess. below is the code.
cmd = ["node", "transformerMonitor.js", "-h", "sample.com", "-s", "123"]
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, text=True)
time_out = 120
start_time = time.time()
while time.time() - start_time < time_out:
out = proc.stdout.readline()
print(out)
if device doesn't respond. out = proc.stdout.readline()
is stuck forever. How to break the loop if there is no response.