@@ -140,20 +140,18 @@ def exec_js_process(js_text, timeout=None, js_console=False, context=None, force
140140 else :
141141 js_engine = 'cwlNodeEngine.js'
142142
143- if localdata .procs .get (js_engine ) is None \
143+ created_new_process = False
144+
145+ if (context is None and localdata .procs .get (js_engine ) is None ) \
146+ or (context is not None and localdata .procs .get ((js_engine , context )) is None ) \
144147 or localdata .procs [js_engine ].poll () is not None \
145148 or onWindows ():
146149 res = resource_stream (__name__ , js_engine )
147150 js_engine_code = res .read ().decode ('utf-8' )
148151
152+ created_new_process = True
153+
149154 localdata .procs [js_engine ] = new_js_proc (js_engine_code , force_docker_pull = force_docker_pull )
150- if context is not None :
151- output = exec_js_process (context , timeout = timeout , js_console = js_console , context = context , force_docker_pull = force_docker_pull , debug = debug )
152- if output != (0 , "" , "" ):
153- # restart to reset the context
154- localdata .procs [js_engine ].kill ()
155- del localdata .procs [js_engine ]
156- return output
157155
158156 nodejs = localdata .procs [js_engine ]
159157
@@ -173,7 +171,12 @@ def terminate():
173171 tm = threading .Timer (timeout , terminate )
174172 tm .start ()
175173
176- stdin_buf = BytesIO ((json .dumps (js_text ) + "\n " ).encode ('utf-8' ))
174+ stdin_text = ""
175+ if created_new_process and context is not None :
176+ stdin_text = json .dumps (context ) + "\n "
177+ stdin_text += json .dumps (js_text ) + "\n "
178+
179+ stdin_buf = BytesIO (stdin_text .encode ('utf-8' ))
177180 stdout_buf = BytesIO ()
178181 stderr_buf = BytesIO ()
179182
0 commit comments