File tree Expand file tree Collapse file tree 1 file changed +8
-4
lines changed
Expand file tree Collapse file tree 1 file changed +8
-4
lines changed Original file line number Diff line number Diff line change @@ -367,6 +367,14 @@ async def execute(
367367 )
368368 await execution .queue .put (UnexpectedEndOfExecution ())
369369
370+ # Schedule env var cleanup inside the lock so the next execution
371+ # can wait for it. The task sends reset code to the kernel, which
372+ # queues it after the current execution's code.
373+ if env_vars :
374+ self ._cleanup_task = asyncio .create_task (
375+ self ._cleanup_env_vars (env_vars )
376+ )
377+
370378 # Stream the results without holding the lock
371379 try :
372380 async for item in self ._wait_for_result (message_id ):
@@ -375,10 +383,6 @@ async def execute(
375383 if message_id in self ._executions :
376384 del self ._executions [message_id ]
377385
378- # Clean up env vars in a separate request after the main code has run
379- if env_vars :
380- self ._cleanup_task = asyncio .create_task (self ._cleanup_env_vars (env_vars ))
381-
382386 async def _receive_message (self ):
383387 if not self ._ws :
384388 logger .error ("No WebSocket connection" )
You can’t perform that action at this time.
0 commit comments