Skip to content

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.

fix(backend): Cleanup service on service closure (#9735)

Zamil Majdy200e5814b3dc
diff --git a/autogpt_platform/backend/backend/util/process.py b/autogpt_platform/backend/backend/util/process.py
index cb4f684663..17e0616c25 100644
--- a/autogpt_platform/backend/backend/util/process.py
+++ b/autogpt_platform/backend/backend/util/process.py
@@ -28,6 +28,7 @@ class AppProcess(ABC):
"""
process: Optional[Process] = None
+ cleaned_up = False
set_start_method("spawn", force=True)
configure_logging()
@@ -62,6 +63,7 @@ class AppProcess(ABC):
def execute_run_command(self, silent):
signal.signal(signal.SIGTERM, self._self_terminate)
+ signal.signal(signal.SIGINT, self._self_terminate)
try:
if silent:
@@ -73,9 +75,16 @@ class AppProcess(ABC):
self.run()
except (KeyboardInterrupt, SystemExit) as e:
logger.warning(f"[{self.service_name}] Terminated: {e}; quitting...")
+ finally:
+ if not self.cleaned_up:
+ self.cleanup()
+ self.cleaned_up = True
+ logger.info(f"[{self.service_name}] Terminated.")
def _self_terminate(self, signum: int, frame):
- self.cleanup()
+ if not self.cleaned_up:
+ self.cleanup()
+ self.cleaned_up = True
sys.exit(0)
# Methods that are executed OUTSIDE the process #