From 701a9e1335f29999df44b2db7edad71b21cc05bf Mon Sep 17 00:00:00 2001 From: spacemanspiff2007 <10754716+spacemanspiff2007@users.noreply.github.com> Date: Wed, 31 Jan 2024 15:50:14 +0100 Subject: [PATCH] Update client.py Fixes x268 --- aiomqtt/client.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/aiomqtt/client.py b/aiomqtt/client.py index 35f8536..4048fd8 100644 --- a/aiomqtt/client.py +++ b/aiomqtt/client.py @@ -233,7 +233,7 @@ def __init__( # noqa: C901, PLR0912, PLR0913, PLR0915 if max_queued_incoming_messages is None: max_queued_incoming_messages = 0 self._queue = queue_type(maxsize=max_queued_incoming_messages) - self.messages = self._messages() + self.messages: AsyncGenerator[Message, None] | None = None # Semaphore to limit the number of concurrent outgoing calls self._outgoing_calls_sem: asyncio.Semaphore | None @@ -705,6 +705,8 @@ async def __aenter__(self) -> Self: # Reset `_disconnected` if it's already in completed state after connecting if self._disconnected.done(): self._disconnected = asyncio.Future() + + self.messages = self._messages() return self async def __aexit__( @@ -714,6 +716,9 @@ async def __aexit__( tb: TracebackType | None, ) -> None: """Disconnect from the broker.""" + + self.messages = None + if self._disconnected.done(): # Return early if the client is already disconnected if self._lock.locked():