-
Notifications
You must be signed in to change notification settings - Fork 76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Broken messages generator with client context re-use #268
Comments
Hi there, Thanks for opening this issue, good find! 👍
The client context manager is reusable, so we should also be able to reuse Apart from that, I wonder if we should start allowing the use of import asyncio
import aiomqtt
async def main():
client = aiomqtt.Client("test.mosquitto.org")
async with client:
await client.subscribe("humidity/#")
await asyncio.sleep(5)
async for message in client.messages:
print(message.payload)
asyncio.run(main()) This is related to #48 which argues that we should allow calls to This would require that the Edit: Our current implementation of |
I'm hit by this issue after updating to 2.0, too.
It makes sense that Binding both |
Hi, the client context reconnect example in reconnection.html does not work as expected in my testing due to what looks like reuse of an invalidated messages generator.
To see the issue in action, add a few print statements to the example code, run it and trigger a re-connect:
This first time through, the async for loop works as expected, but when the client is re-used after a loss of connection, the messages generator ends and the code will loop connecting then immediately disconnecting.
Sorry, I'm not sure where the fix for this ought to go, nor what the proper use of the client.messages should to be - but the following change seems to work:
Alternatively, adjusting the example code for loop as follows also works:
async for message in client._messages():
Setup:
The text was updated successfully, but these errors were encountered: