-
Notifications
You must be signed in to change notification settings - Fork 79
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
Update client.py #271
Update client.py #271
Conversation
Fixes x268
I tried to add it but I am not fully sure if everything is in the right place ... . |
Thanks for another PR from you! 🎸
I see this now as well. It also messes up the typing (I'm no pro with typing in Python, so could be that we can do this differently as well). The underlying problem is that generators in Python are invalidated once they throw an exception. It's possible to hack around this, but that will only be confusing in the end. I think the way forward could be to rename async with aiomqtt.Client("test.mosquitto.org") as client:
await client.subscribe("temperature/#")
async for message in client.messages():
print(message.payload) Which is a breaking change. That's on me for not catching this issue when I implemented v2.0.0, sorry about that! I think the best way for now is to use |
For me this is not an issue because I'm using a workaround. However I think I don't think using |
aiomqtt/client.py
Outdated
@@ -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() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think assigning messages
in aenter and aexit is the best way to solve this problem.
This will not create disruptive changes, Just like _disconnected
and _lock
are reassigned at aenter and aexit.
It seems that adding reusable features pits us. This means that in the future, when initializing the Client class, all the class properties that need to be instantiated need to be taken care of to make sure that reusable does not cause problems. |
Imho |
I believe that this is fixed with #312. I only just now saw the additional commit with the migration suggestion you made, Thank you for the work you put into this PR nonetheless!
That's a really good example! Like |
Fixes #268