Skip to content

Commit 828e48a

Browse files
Kill Docker container if --cidfile is specified (#996)
1 parent e9ee415 commit 828e48a

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

cwltool/main.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import logging
99
import os
1010
import signal
11+
import subprocess # nosec
1112
import sys
1213
import time
1314
import urllib
@@ -112,7 +113,18 @@ def _terminate_processes() -> None:
112113
# It's possible that another thread will spawn a new task while
113114
# we're executing, so it's not safe to use a for loop here.
114115
while processes_to_kill:
115-
processes_to_kill.popleft().kill()
116+
process = processes_to_kill.popleft()
117+
cidfile = [str(arg).split("=")[1] for arg in process.args if "--cidfile" in str(arg)]
118+
if cidfile:
119+
try:
120+
with open(cidfile[0], "r") as inp_stream:
121+
p = subprocess.Popen(["docker", "kill", inp_stream.read()], shell=False) # nosec
122+
try:
123+
p.wait(timeout=10)
124+
except subprocess.TimeoutExpired:
125+
p.kill()
126+
except FileNotFoundError:
127+
pass
116128

117129

118130
def _signal_handler(signum: int, _: Any) -> None:

0 commit comments

Comments
 (0)