optimize(sandbox): cleanup docker when disconnect to speed up restart speed (#557)

* clean docker when disconnect

* add check
This commit is contained in:
Yufan Song
2024-04-02 14:57:16 -07:00
committed by GitHub
parent b6b7272cdc
commit 1af287a24b

View File

@@ -97,10 +97,8 @@ class Session:
await self.send_error("I didn't recognize this action:" + action)
except WebSocketDisconnect as e:
self.websocket = None
if self.agent_task:
self.agent_task.cancel()
print("Client websocket disconnected", e)
self.disconnect()
async def create_controller(self, start_event=None):
"""Creates an AgentController instance.
@@ -175,3 +173,10 @@ class Session:
return
event_dict = event.to_dict()
asyncio.create_task(self.send(event_dict), name="send event in callback")
def disconnect(self):
self.websocket = None
if self.agent_task:
self.agent_task.cancel()
if self.controller is not None:
self.controller.command_manager.shell.close()