@@ -42,7 +42,7 @@ def check_js_threshold_version(working_alias):
42
42
"""
43
43
# parse nodejs version into int Tuple: 'v4.2.6\n' -> [4, 2, 6]
44
44
current_version_str = subprocess .check_output (
45
- [working_alias , "-v" ]).decode ('ascii ' )
45
+ [working_alias , "-v" ]).decode ('utf-8 ' )
46
46
47
47
current_version = [int (v ) for v in current_version_str .strip ().strip ('v' ).split ('.' )]
48
48
minimum_node_version = [int (v ) for v in minimum_node_version_str .split ('.' )]
@@ -64,7 +64,7 @@ def new_js_proc():
64
64
trynodes = ("nodejs" , "node" )
65
65
for n in trynodes :
66
66
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" :
68
68
continue
69
69
else :
70
70
nodejs = subprocess .Popen ([n , "--eval" , nodecode ],
@@ -87,9 +87,11 @@ def new_js_proc():
87
87
nodeimg = "node:slim"
88
88
global have_node_slim
89
89
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
91
92
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' )
93
95
_logger .info ("Pulled Docker image %s %s" , nodeimg , nodejsimg )
94
96
have_node_slim = True
95
97
nodejs = subprocess .Popen (["docker" , "run" ,
@@ -134,7 +136,8 @@ def execjs(js, jslib, timeout=None, debug=False): # type: (Union[Mapping, Text]
134
136
135
137
killed = []
136
138
137
- def term ():
139
+ """ Kill the node process if it exceeds timeout limit"""
140
+ def terminate ():
138
141
try :
139
142
killed .append (True )
140
143
nodejs .kill ()
@@ -144,7 +147,7 @@ def term():
144
147
if timeout is None :
145
148
timeout = 20
146
149
147
- tm = threading .Timer (timeout , term )
150
+ tm = threading .Timer (timeout , terminate )
148
151
tm .start ()
149
152
150
153
stdin_buf = BytesIO ((json .dumps (fn ) + "\n " ).encode ('utf-8' ))
@@ -154,7 +157,8 @@ def term():
154
157
rselect = [nodejs .stdout , nodejs .stderr ] # type: List[BytesIO]
155
158
wselect = [nodejs .stdin ] # type: List[BytesIO]
156
159
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)
158
162
if sys .platform == 'win32' :
159
163
READ_BYTES_SIZE = 512
160
164
0 commit comments