-
Notifications
You must be signed in to change notification settings - Fork 725
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
Fix loop_stop() not clearing ._thread when called from same thread #809
Conversation
When loop_stop is called from within on_message(), ._thread will not be set to None. This will cause subsequent loop_start() to return an error.
Context: For shutdown, this pull request is necessary to address the issue directly without creating a workaround. For restart, we have to call reboot from a different thread. For example:
|
Hello, thanks for your contribution. For a contribution to be merged, you will need to sign the Eclipse ECA for your contribution to be merged. (https://accounts.eclipse.org/user/eca) That being said, if I understand correctly your use-case, you do not want to (just) call loop_stop/loop_start. This will mostly do nothing, it do not disconnect from MQTT (so it don't simulate a device reboot). I'm not sure if could be valid to call loop_stop & loop_start within a callback. Because to call loop_start I believe it's required to have the thread stopped (or else it will be too complex regarding possible race-condition), and the thread won't stop until the callback returned. Actually if you want to simulate de device reboot, you should also discard the Client state (like the possibly queued message), for that the best solution would be to re-create the Client(). For this the best solution IMO is doing something like:
Does this solve your problem ? |
Hi Pierre, I have signed the ECA. For restart, I have already assessed and agree that there is no meaningful way to implement it in PahoMQTT's on_message() callback. I simply wanted to provide some context for the error we faced. We are fine with creating a separate thread. For shutdown, I believe it should be valid for loop_stop() to be called from on_message() callback. But there is currently an error without this pull request. |
Thank for your patience. I do have fear that your solution will introduce new bugs, mostly because the thread will still be running with If I get correctly the aim of this fix (being able to call This should also make the "later" to call |
Hi Pierre. I have updated the code as suggested. However, I am unsure where to insert a try/finally block. Do let me know if any other changes are required |
When client.loop_stop() is called from within on_message() callback, client ._thread will not be set to None. This will cause subsequent loop_start() to return MQTT_ERR_INVAL error.