Skip to content

Commit

Permalink
optimize(sandbox): cleanup docker when disconnect to speed up restart…
Browse files Browse the repository at this point in the history
… speed (All-Hands-AI#557)

* clean docker when disconnect

* add check
  • Loading branch information
yufansong committed Apr 2, 2024
1 parent b6b7272 commit 1af287a
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions opendevin/server/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,8 @@ async def start_listening(self):
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.
Expand Down Expand Up @@ -175,3 +173,10 @@ def on_agent_event(self, event: Observation | Action):
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()

0 comments on commit 1af287a

Please sign in to comment.