AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
Enhance process management with error handling and lifecycle improvements (#9565)
Libin Rahman09494809c131
diff --git a/autogpt_platform/backend/backend/app.py b/autogpt_platform/backend/backend/app.pyindex eb0c6370c6..d028924be7 100644--- a/autogpt_platform/backend/backend/app.py+++ b/autogpt_platform/backend/backend/app.py@@ -1,22 +1,30 @@+import loggingfrom typing import TYPE_CHECKINGif TYPE_CHECKING:from backend.util.process import AppProcess+logger = logging.getLogger(__name__)+def run_processes(*processes: "AppProcess", **kwargs):"""Execute all processes in the app. The last process is run in the foreground.+ Includes enhanced error handling and process lifecycle management."""try:+ # Run all processes except the last one in the background.for process in processes[:-1]:process.start(background=True, **kwargs)- # Run the last process in the foreground+ # Run the last process in the foreground.processes[-1].start(background=False, **kwargs)finally:for process in processes:- process.stop()+ try:+ process.stop()+ except Exception as e:+ logger.exception(f"[{process.service_name}] unable to stop: {e}")def main(**kwargs):diff --git a/autogpt_platform/backend/backend/util/process.py b/autogpt_platform/backend/backend/util/process.pyindex 530c756ef9..cb4f684663 100644--- a/autogpt_platform/backend/backend/util/process.py+++ b/autogpt_platform/backend/backend/util/process.py@@ -109,6 +109,8 @@ class AppProcess(ABC):)self.process.start()self.health_check()+ logger.info(f"[{self.service_name}] started with PID {self.process.pid}")+return self.process.pid or 0def stop(self):@@ -120,4 +122,6 @@ class AppProcess(ABC):self.process.terminate()self.process.join()++ logger.info(f"[{self.service_name}] with PID {self.process.pid} stopped")self.process = None