Black Lives Matter - Action and Equality. ... Adafruit is open and shipping.
0

Python library - a question & maybe a request
Moderators: adafruit_support_bill, adafruit

Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.
Please be positive and constructive with your questions and comments.

Python library - a question & maybe a request

by krambriw on Tue Apr 05, 2016 3:30 am

Hello,

I am running the python Adafruit MQTT Client as a sub-process in a Python framework. For what ever reason, users sometimes like to stop the Adafruit MQTT Client but since there is no method to stop the background thread started by the call to loop_background() it continues running. To terminate it, I have to end the whole framework.

Would it be possible to modify the library so that it also includes a stop method (is actually already supported by paho)??? Eventually you could consider to add a call to client.loop_stop() internally when calling client.disconnect() but that might break some other fellows implementations

As example:

client.loop_background()
.....

client.loop_stop()

As a work-around I have defined a separate thread in my code that instead uses client.loop() but it would be nicer to use the foreseen client.loop_background()

Kind regards, Walter

krambriw
 
Posts: 22
Joined: Fri Feb 19, 2016 6:07 pm

Re: Python library - a question & maybe a request

by krambriw on Tue Apr 05, 2016 4:22 am

Just additional info. I made a temporary fix and added the following to your mqtt_client.py and it seems to work fine

Code: Select all | TOGGLE FULL SIZE
    def loop_stop(self):
        """Stops a background thread from listen for messages from Adafruit.IO
        """
        self._client.loop_stop()


krambriw
 
Posts: 22
Joined: Fri Feb 19, 2016 6:07 pm

Please be positive and constructive with your questions and comments.