Sfoglia il codice sorgente

opendevin/core/main.py: Graceful shutdown (#1731)

* opendevin/core/main.py: Graceful shutdown

* Shutdown controller at exit

* Update opendevin/core/main.py

---------

Co-authored-by: Yufan Song <33971064+yufansong@users.noreply.github.com>
Co-authored-by: Graham Neubig <neubig@gmail.com>
Boxuan Li 1 anno fa
parent
commit
49de262577
2 ha cambiato i file con 8 aggiunte e 7 eliminazioni
  1. 6 3
      opendevin/core/main.py
  2. 2 4
      tests/integration/test_agent.py

+ 6 - 3
opendevin/core/main.py

@@ -25,8 +25,11 @@ def read_task_from_stdin() -> str:
     return sys.stdin.read()
 
 
-async def main(task_str: str = ''):
-    """Main coroutine to run the agent controller with task input flexibility."""
+async def main(task_str: str = '') -> None:
+    """
+    Main coroutine to run the agent controller with task input flexibility.
+    It's only used when you launch opendevin backend directly via cmdline.
+    """
 
     # Determine the task source
     if task_str:
@@ -94,7 +97,7 @@ async def main(task_str: str = ''):
     ]:
         await asyncio.sleep(1)  # Give back control for a tick, so the agent can run
 
-    return controller
+    await controller.close()
 
 
 if __name__ == '__main__':

+ 2 - 4
tests/integration/test_agent.py

@@ -17,8 +17,7 @@ workspace_base = os.getenv('WORKSPACE_BASE')
 )
 def test_write_simple_script():
     task = "Write a shell script 'hello.sh' that prints 'hello'. Do not ask me for confirmation at any point."
-    controller = asyncio.run(main(task))
-    asyncio.run(controller.close())
+    asyncio.run(main(task))
 
     # Verify the script file exists
     script_path = os.path.join(workspace_base, 'hello.sh')
@@ -58,8 +57,7 @@ def test_edits():
 
     # Execute the task
     task = 'Fix typos in bad.txt. Do not ask me for confirmation at any point.'
-    controller = asyncio.run(main(task))
-    asyncio.run(controller.close())
+    asyncio.run(main(task))
 
     # Verify bad.txt has been fixed
     text = """This is a stupid typo.