Skip to content

Commit e199ba6

Browse files
committed
Fix issue #947. Wait for "docker run" process to exit after its
child (processor) process exits before deciding that an error has occurred.
1 parent ec5248c commit e199ba6

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

tools/imagesets/imgset.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,21 @@ def run_with_logging(dockercall, cmd, logger, printlog=True):
3636
printlog : boolean, optional
3737
Print log to console
3838
"""
39+
import datetime;
3940
logger.propagate = printlog
4041
# remove extra whitespace
4142
normalize = lambda s: subprocess.list2cmdline(shlex.split(s))
4243
# format command string for logging
4344
cmdstr = normalize(dockercall) + ' "\n' + ''.join(f'{"":<6}{normalize(c)}\n' for c in cmd) + '"'
4445
# save command to log
4546
logger.info("++ " + cmdstr + "\n")
46-
pipe = subprocess.Popen(shlex.split(cmdstr), stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
47+
pipe = subprocess.Popen(shlex.split(cmdstr), stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=False)
48+
49+
# Maximum number of seconds to wait for "docker run" to finish after
50+
# its child process exits. The observed times have been < 1 ms.
51+
# Use a relatively large number to flag a possible problem with Docker.
52+
timeout = 10
53+
4754
with pipe.stdout:
4855
for line in iter(pipe.stdout.readline, b''): # b'\n'-separated lines
4956
decoded = line.decode("utf-8")
@@ -52,7 +59,12 @@ def run_with_logging(dockercall, cmd, logger, printlog=True):
5259
decoded = decoded[:-1]
5360
logger.info(decoded)
5461
ret = pipe.poll()
55-
if ret != 0:
62+
if ret == None:
63+
ret = pipe.wait(timeout=timeout)
64+
# ret will be None if exception TimeoutExpired was raised and caught.
65+
if ret != 0:
66+
raise subprocess.CalledProcessError(ret, cmdstr)
67+
elif ret != 0:
5668
raise subprocess.CalledProcessError(ret, cmdstr)
5769

5870
# A set of docker images suitable for building and running isce3
@@ -670,12 +682,9 @@ def prdocs(self):
670682

671683
def tartests(self):
672684
"""
673-
Tar up test directories for delivery. PGE has requested that
674-
the scratch directory contents be excluded from the deliveries.
675-
Include the scratch directories only as empty directories to
676-
maintain consistency with the runconfigs.
685+
Tar up test directories for delivery
677686
"""
678687
for workflow in workflowtests:
679688
for test in workflowtests[workflow]:
680689
print(f"\ntarring workflow test {test}\n")
681-
subprocess.check_call(f"tar cvz --exclude scratch*/* -f {test}.tar.gz {test}".split(), cwd=self.testdir)
690+
subprocess.check_call(f"tar cvzf {test}.tar.gz {test}".split(), cwd=self.testdir)

0 commit comments

Comments
 (0)