diff --git a/src/__init__.py b/src/__init__.py index 8a0f8916..af917a1b 100644 --- a/src/__init__.py +++ b/src/__init__.py @@ -57,7 +57,7 @@ from testgres.operations.local_ops import LocalOperations from testgres.operations.remote_ops import RemoteOperations -__version__ = "1.15.1" +__version__ = "1.15.2" __all__ = [ "get_new_node", diff --git a/src/logger.py b/src/logger.py index 51e11b73..333da71c 100644 --- a/src/logger.py +++ b/src/logger.py @@ -31,7 +31,7 @@ def __init__( assert type(log_file_encoding) is str assert os_ops is None or isinstance(os_ops, OsOperations) - threading.Thread.__init__(self) + threading.Thread.__init__(self, daemon=True) if os_ops is None: os_ops = tconf.os_ops diff --git a/src/node.py b/src/node.py index 4bdd88d6..b369c73a 100644 --- a/src/node.py +++ b/src/node.py @@ -638,6 +638,12 @@ def _try_shutdown(self, max_attempts, with_force=False): assert type(with_force) is bool assert max_attempts > 0 + try: + self._try_shutdown_internal(max_attempts, with_force) + finally: + self._maybe_stop_logger() + + def _try_shutdown_internal(self, max_attempts, with_force): attempts = 0 # try stopping server N times @@ -1331,11 +1337,13 @@ def stop(self, params=[], wait=True): "stop" ] + params # yapf: disable - execute_utility2(self._os_ops, _params, self.utils_log_file) - - self._manually_started_pm_pid = None - - self._maybe_stop_logger() + try: + execute_utility2(self._os_ops, _params, self.utils_log_file) + self._manually_started_pm_pid = None + finally: + # always stop the reader thread, even if pg_ctl stop failed, + # so it can't leak into interpreter shutdown. + self._maybe_stop_logger() return self def kill(self, someone=None):