diff --git a/h3daemon/h3daemon/daemon.py b/h3daemon/h3daemon/daemon.py index 38608ab..4462968 100644 --- a/h3daemon/h3daemon/daemon.py +++ b/h3daemon/h3daemon/daemon.py @@ -17,17 +17,19 @@ __all__ = ["Daemon", "daemon_context"] -def shutdown(x: psutil.Process, force: bool): +def shutdown(x: psutil.Process, *, force: bool, wait: bool): with suppress(psutil.NoSuchProcess): if force: x.kill() - x.wait() + if wait: + x.wait() else: x.terminate() try: - x.wait(3) + if wait: + x.wait(5) except psutil.TimeoutExpired: - shutdown(x, True) + shutdown(x, force=True, wait=wait) class Daemon: @@ -63,9 +65,9 @@ def spawn(cls, hmmfile: HMMFile, cport: int = 0, wport: int = 0): except Exception as exception: debug_exception(exception) if worker: - shutdown(worker.process, force=True) + shutdown(worker.process, force=True, wait=False) if master: - shutdown(master.process, force=True) + shutdown(master.process, force=True, wait=False) raise exception return cls(master, worker, None) @@ -99,14 +101,14 @@ def possess(cls, pidfile: PIDLockFile): return cls(master, worker, process) def shutdown(self, force=False): - if self._worker is not None: - shutdown(self._worker.process, True) - if self._master is not None: - shutdown(self._master.process, True) + shutdown(self._master.process, force=force, wait=False) + + if self._worker is not None: + shutdown(self._worker.process, force=force, wait=False) if self._process is not None: - shutdown(self._process, force) + shutdown(self._process, force=force, wait=True) debug_message("Daemon.shutdown finished") diff --git a/h3daemon/pyproject.toml b/h3daemon/pyproject.toml index a414e0b..b9d494b 100644 --- a/h3daemon/pyproject.toml +++ b/h3daemon/pyproject.toml @@ -22,7 +22,6 @@ cli = ["typer"] [tool.poetry.group.dev.dependencies] pytest-repeat = "^0.9.3" pytest = "^8.3.4" -pytest-xdist = "^3.6.1" [build-system] requires = ["poetry-core"]