]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#2696] hammer.py: check Popen.poll() at the end
authorAndrei Pavel <andrei@isc.org>
Wed, 25 Jan 2023 22:12:05 +0000 (00:12 +0200)
committerAndrei Pavel <andrei@isc.org>
Fri, 3 Feb 2023 14:57:09 +0000 (16:57 +0200)
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.

hammer.py

index 01eaf489be837d2ba52ef0f2793798c876aef9ab..0dae1cf647d8a19571c690ac27356ce3571d3b61 100755 (executable)
--- a/hammer.py
+++ b/hammer.py
@@ -361,9 +361,8 @@ def execute(cmd, timeout=60, cwd=None, env=None, raise_error=True, dry_run=False
             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'
@@ -374,6 +373,8 @@ def execute(cmd, timeout=60, cwd=None, env=None, raise_error=True, dry_run=False
                     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.