Skip to content

Commit 8167609

Browse files
committed
move clean up back to original place
1 parent e4ca40b commit 8167609

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

template/server/messaging.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff 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")

0 commit comments

Comments
 (0)