From 827b56400675acb2f601a2be88cb48109a777925 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Sun, 13 Aug 2023 22:20:16 +0200 Subject: [PATCH] Using a single constant for DEFAULT_REDIS_QUEUE. Also, catch `AttributeError` on `self._proc.terminate` in the `HttpBackend`, since the process may already have been terminated and set to null by another worker process. --- platypush/app.py | 5 +---- platypush/backend/http/__init__.py | 8 ++++++-- platypush/bus/redis.py | 6 +++--- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/platypush/app.py b/platypush/app.py index cea035c72..9f6151b5a 100644 --- a/platypush/app.py +++ b/platypush/app.py @@ -25,9 +25,6 @@ log = logging.getLogger('platypush') class Application: """Main class for the Platypush application.""" - # Default bus queue name - _default_redis_queue = 'platypush/bus' - # Default Redis port _default_redis_port = 6379 @@ -90,7 +87,7 @@ class Application: f.write(str(os.getpid())) self.bus: Optional[Bus] = None - self.redis_queue = redis_queue or self._default_redis_queue + self.redis_queue = redis_queue or RedisBus.DEFAULT_REDIS_QUEUE self.config_file = config_file self._verbose = verbose self._logsdir = ( diff --git a/platypush/backend/http/__init__.py b/platypush/backend/http/__init__.py index 4df3ce8a7..12ce9f2c5 100644 --- a/platypush/backend/http/__init__.py +++ b/platypush/backend/http/__init__.py @@ -269,8 +269,12 @@ class HttpBackend(Backend): self._workers.pop(i) if self._server_proc: - self._server_proc.terminate() - self._server_proc.join(timeout=5) + try: + self._server_proc.terminate() + self._server_proc.join(timeout=5) + except AttributeError: + pass + self._server_proc = None if self._server_proc and self._server_proc.is_alive(): diff --git a/platypush/bus/redis.py b/platypush/bus/redis.py index e8273a126..83ded8aff 100644 --- a/platypush/bus/redis.py +++ b/platypush/bus/redis.py @@ -1,6 +1,6 @@ import logging import threading -from typing import Optional +from typing import Final, Optional from platypush.bus import Bus from platypush.message import Message @@ -13,7 +13,7 @@ class RedisBus(Bus): Overrides the in-process in-memory local bus with a Redis bus """ - _DEFAULT_REDIS_QUEUE = 'platypush/bus' + DEFAULT_REDIS_QUEUE: Final[str] = 'platypush/bus' def __init__(self, *args, on_message=None, redis_queue=None, **kwargs): from platypush.utils import get_redis @@ -21,7 +21,7 @@ class RedisBus(Bus): super().__init__(on_message=on_message) self.redis = get_redis(*args, **kwargs) self.redis_args = kwargs - self.redis_queue = redis_queue or self._DEFAULT_REDIS_QUEUE + self.redis_queue = redis_queue or self.DEFAULT_REDIS_QUEUE self.on_message = on_message self.thread_id = threading.get_ident()