From f1acff00e9b1e7b8ba082b982b8c468b5a7c1fe7 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Mon, 4 Sep 2023 11:01:34 +0200 Subject: [PATCH] Put the join back on `CommandStream.__exit__`. We want to give the process a bit of slack between the terminate and the close, or we'll be guaranteed to get race conditions upon close. --- platypush/commands/_stream.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/platypush/commands/_stream.py b/platypush/commands/_stream.py index b4b120142..99d12b4c9 100644 --- a/platypush/commands/_stream.py +++ b/platypush/commands/_stream.py @@ -34,7 +34,7 @@ class CommandStream(ControllableProcess): super().__init__(name='platypush:cmd:stream') self.path = os.path.abspath(os.path.expanduser(path or self._default_sock_path)) self._sock: Optional[socket.socket] = None - self._cmd_queue: Queue["Command"] = Queue() + self._cmd_queue = Queue() self._close_lock = RLock() def reset(self): @@ -71,16 +71,21 @@ class CommandStream(ControllableProcess): def __exit__(self, *_, **__): with self._close_lock: self.terminate() + self.join(1) try: self.close() except Exception as e: - self.logger.warning(str(e)) + self.logger.warning( + '%s on command stream close: %s', type(e).__name__, str(e) + ) try: self.kill() except Exception as e: - self.logger.warning(str(e)) + self.logger.debug( + '%s on command stream kill: %s', type(e).__name__, str(e) + ) def _serve(self, sock: socket.socket): """