From 291edf7ee6bb1a36354dbbdefcbb863b2180615b Mon Sep 17 00:00:00 2001 From: angrybayblade Date: Fri, 31 May 2024 14:41:31 +0530 Subject: [PATCH] fix: agent and tendermint process kill logic --- operate/services/service.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/operate/services/service.py b/operate/services/service.py index 05411d6dc..5309f158c 100644 --- a/operate/services/service.py +++ b/operate/services/service.py @@ -25,6 +25,7 @@ import shutil import signal import subprocess # nosec +import time import typing as t from copy import deepcopy from dataclasses import dataclass @@ -427,9 +428,19 @@ def _start_tendermint(working_dir: Path) -> None: def _kill_process(pid: int) -> None: """Kill process.""" - if platform.platform() == "Windows": - return os.kill(pid, signal.CTRL_C_EVENT) # type: ignore - return os.kill(pid, signal.SIGKILL) + while True: + try: + os.kill( + pid, + ( + signal.CTRL_C_EVENT # type: ignore + if platform.platform() == "Windows" + else signal.SIGKILL + ), + ) + except OSError: + return + time.sleep(3) def _stop_agent(working_dir: Path) -> None: @@ -615,7 +626,9 @@ def _build_host(self, force: bool = True) -> None: build = self.path / DEPLOYMENT if build.exists() and not force: return + if build.exists() and force: + stop_host_deployment(build_dir=build) shutil.rmtree(build) service = Service.load(path=self.path)