There was a wrong assumption that the first call to Popen.poll()
is always None. This is not the case when the process is fast enough
to finish before it gets polled, in which case it is not None, but
it is the return code instead. This caused some executes to have
empty output.
if capture:
output = ''
t0 = time.time()
- t1 = time.time()
# repeat until process is running or timeout not occurred
- while p.poll() is None and (timeout is None or t1 - t0 < timeout):
+ while True:
line = p.stdout.readline()
if line:
line_decoded = line.decode(encoding='ascii', errors='ignore').rstrip() + '\r'
if log_file_path:
log_file.write(line)
t1 = time.time()
+ if p.poll() is not None or (timeout is not None and timeout < t1 - t0):
+ break
# If no exitcode yet, ie. process is still running then it means that timeout occurred.
# In such case terminate the process and raise an exception.