Skip to content

Commit c6d7917

Browse files
authored
Merge pull request #494 from common-workflow-language/nodejs_fix
sandboxjs.py: fix checking condition for node:slim
2 parents d6cbd2b + e1d64d4 commit c6d7917

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

cwltool/sandboxjs.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def check_js_threshold_version(working_alias):
4242
"""
4343
# parse nodejs version into int Tuple: 'v4.2.6\n' -> [4, 2, 6]
4444
current_version_str = subprocess.check_output(
45-
[working_alias, "-v"]).decode('ascii')
45+
[working_alias, "-v"]).decode('utf-8')
4646

4747
current_version = [int(v) for v in current_version_str.strip().strip('v').split('.')]
4848
minimum_node_version = [int(v) for v in minimum_node_version_str.split('.')]
@@ -64,7 +64,7 @@ def new_js_proc():
6464
trynodes = ("nodejs", "node")
6565
for n in trynodes:
6666
try:
67-
if subprocess.check_output([n, "--eval", "process.stdout.write('t')"]) != "t":
67+
if subprocess.check_output([n, "--eval", "process.stdout.write('t')"]).decode('utf-8') != "t":
6868
continue
6969
else:
7070
nodejs = subprocess.Popen([n, "--eval", nodecode],
@@ -87,9 +87,11 @@ def new_js_proc():
8787
nodeimg = "node:slim"
8888
global have_node_slim
8989
if not have_node_slim:
90-
dockerimgs = subprocess.check_output(["docker", "images", nodeimg]).decode('utf-8')
90+
dockerimgs = subprocess.check_output(["docker", "images", "-q", nodeimg]).decode('utf-8')
91+
# if output is an empty string
9192
if len(dockerimgs.split("\n")) <= 1:
92-
nodejsimg = subprocess.check_output(["docker", "pull", nodeimg])
93+
# pull node:slim docker container
94+
nodejsimg = subprocess.check_output(["docker", "pull", nodeimg]).decode('utf-8')
9395
_logger.info("Pulled Docker image %s %s", nodeimg, nodejsimg)
9496
have_node_slim = True
9597
nodejs = subprocess.Popen(["docker", "run",
@@ -134,7 +136,8 @@ def execjs(js, jslib, timeout=None, debug=False): # type: (Union[Mapping, Text]
134136

135137
killed = []
136138

137-
def term():
139+
""" Kill the node process if it exceeds timeout limit"""
140+
def terminate():
138141
try:
139142
killed.append(True)
140143
nodejs.kill()
@@ -144,7 +147,7 @@ def term():
144147
if timeout is None:
145148
timeout = 20
146149

147-
tm = threading.Timer(timeout, term)
150+
tm = threading.Timer(timeout, terminate)
148151
tm.start()
149152

150153
stdin_buf = BytesIO((json.dumps(fn) + "\n").encode('utf-8'))
@@ -154,7 +157,8 @@ def term():
154157
rselect = [nodejs.stdout, nodejs.stderr] # type: List[BytesIO]
155158
wselect = [nodejs.stdin] # type: List[BytesIO]
156159

157-
# On windows system standard input/output are not handled properly by select module(modules like pywin32, msvcrt, gevent don't work either)
160+
# On windows system standard input/output are not handled properly by select module
161+
# (modules like pywin32, msvcrt, gevent don't work either)
158162
if sys.platform=='win32':
159163
READ_BYTES_SIZE = 512
160164

0 commit comments

Comments
 (0)