paho.mqtt.python icon indicating copy to clipboard operation
paho.mqtt.python copied to clipboard

Make use of loop_stop()'s force parameter

Open nakami opened this issue 3 years ago • 2 comments

Currently (v1.5.1), the force parameter in loop_stop does nothing. I ran into an issue where a packet with QoS 2 was sent by the client and does not respond - effectively locking up the client waiting for a response. I am calling Client.loop_stop() to forcefully exit, but loop_stop stalls.

Client.loop_stop() (client.py):

    def loop_stop(self, force=False):
        """This is part of the threaded client interface. Call this once to
        stop the network thread previously created with loop_start(). This call
        will block until the network thread finishes.

        The force parameter is currently ignored.
        """

nakami avatar Oct 08 '21 15:10 nakami

Quick fix for my use-case:

Set the timeout for the join() call to 30 seconds:

        if self.threading.current_thread() != self._thread:
            #self._thread.join()
            self._thread.join(timeout=30.0 if force else None)
            self._thread = None

nakami avatar Oct 08 '21 15:10 nakami

Just noting that this is still the case with @master (it's documented "The force parameter is currently ignored."). I'll flag this as an enhancement.

MattBrittan avatar Jan 07 '24 08:01 MattBrittan