From b92d5f112d60602f6326fb46372045bbc8273889 Mon Sep 17 00:00:00 2001 From: Inada Naoki Date: Thu, 6 Jun 2024 00:30:23 +0900 Subject: [PATCH 1/2] do not create sender at close --- fluent/asynchandler.py | 16 ---------------- fluent/handler.py | 5 ++++- 2 files changed, 4 insertions(+), 17 deletions(-) diff --git a/fluent/asynchandler.py b/fluent/asynchandler.py index 397608e..e3c3dc0 100644 --- a/fluent/asynchandler.py +++ b/fluent/asynchandler.py @@ -8,19 +8,3 @@ class FluentHandler(handler.FluentHandler): def getSenderClass(self): return asyncsender.FluentSender - - def close(self): - self.acquire() - try: - try: - self.sender.close() - finally: - super().close() - finally: - self.release() - - def __enter__(self): - return self - - def __exit__(self, exc_type, exc_val, exc_tb): - self.close() diff --git a/fluent/handler.py b/fluent/handler.py index 1018d69..5964fa6 100644 --- a/fluent/handler.py +++ b/fluent/handler.py @@ -264,7 +264,10 @@ def close(self): self.acquire() try: try: - self.sender.close() + s = self._sender + self._sender = None + if s is not None: + s.close() finally: super().close() finally: From 2600ddc3fe87a38525823dfe674a87cf5c598811 Mon Sep 17 00:00:00 2001 From: Inada Naoki Date: Thu, 6 Jun 2024 23:22:51 +0900 Subject: [PATCH 2/2] reduce code --- fluent/handler.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/fluent/handler.py b/fluent/handler.py index 5964fa6..8029604 100644 --- a/fluent/handler.py +++ b/fluent/handler.py @@ -264,10 +264,9 @@ def close(self): self.acquire() try: try: - s = self._sender - self._sender = None - if s is not None: - s.close() + if self._sender is not None: + self._sender.close() + self._sender = None finally: super().close() finally: