From 9289cde4ee6b238e14e83cc74fcc717252874774 Mon Sep 17 00:00:00 2001 From: mle Date: Tue, 21 May 2024 22:26:20 +0200 Subject: [PATCH] Check the future state when setting exception --- goodwe/protocol.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/goodwe/protocol.py b/goodwe/protocol.py index 6f288c4..f801d20 100644 --- a/goodwe/protocol.py +++ b/goodwe/protocol.py @@ -146,7 +146,8 @@ def datagram_received(self, data: bytes, addr: Tuple[str, int]) -> None: logger.debug("Response already handled: %s", data.hex()) except RequestRejectedException as ex: logger.debug("Received exception response: %s", data.hex()) - self.response_future.set_exception(ex) + if self.response_future and not self.response_future.done(): + self.response_future.set_exception(ex) self._close_transport() def error_received(self, exc: Exception) -> None: @@ -290,7 +291,8 @@ def data_received(self, data: bytes) -> None: logger.debug("Response already handled: %s", data.hex()) except RequestRejectedException as ex: logger.debug("Received exception response: %s", data.hex()) - self.response_future.set_exception(ex) + if self.response_future and not self.response_future.done(): + self.response_future.set_exception(ex) # self._close_transport() def error_received(self, exc: Exception) -> None: