From 513830b1b11c5b6f111779c86c6d1e3228b62468 Mon Sep 17 00:00:00 2001 From: Jusong Yu Date: Thu, 11 May 2023 10:52:23 +0200 Subject: [PATCH] `DaemonClient`: Clean stale PID file in `stop_daemon` (#6007) The daemon client was recently refactored to only clean the stale PID file in the `start_daemon` command. Before it was done when asking the status which was considered an unexpected side-effect. Sometimes, the user wants to make sure the daemon is no longer running. Currently, the status would raise a warning if a stale PID file is found suggesting the user to start the daemon to fix it. However, this is counterintuitve and not desirable if the goal is for the daemon to be stopped. The `stop_daemon` method is updated to also clean any potentially stale PID files. The error message is updated to suggest to either start or stop the daemon to return it to a nominal state. Co-authored-by: Sebastiaan Huber Cherry-pick: 2bfc3c6a8ce4100a53fe9842835d5b7a03b1bd29 --- aiida/engine/daemon/client.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/aiida/engine/daemon/client.py b/aiida/engine/daemon/client.py index c5314e7936..e829c7dae6 100644 --- a/aiida/engine/daemon/client.py +++ b/aiida/engine/daemon/client.py @@ -424,8 +424,8 @@ def call_client(self, command: dict[str, t.Any], timeout: int | None = None) -> if self._is_pid_file_stale: raise DaemonStalePidException( - 'The daemon could not be reached, seemingly because of a stale PID file. Try starting the daemon ' - 'to remove it and restore the daemon.' + 'The daemon could not be reached, seemingly because of a stale PID file. Either stop or start the ' + 'daemon to remove it and restore the daemon to a functional state.' ) from exception if str(exception) == 'Timed out.': @@ -557,6 +557,8 @@ def stop_daemon(self, wait: bool = True, timeout: int | None = None) -> dict[str :raises DaemonTimeoutException: If the connection to the daemon timed out. :raises DaemonException: If the connection to the daemon failed for any other reason. """ + self._clean_potentially_stale_pid_file() + command = {'command': 'quit', 'properties': {'waiting': wait}} response = self.call_client(command, timeout=timeout)