Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Paho » Paho connection/disconnection freezing(Python mqtt paho: thread no more responding while trying to connect/disconnect)
Paho connection/disconnection freezing [message #1841195] Thu, 06 May 2021 07:50 Go to next message
Tom Vandenbussche is currently offline Tom VandenbusscheFriend
Messages: 3
Registered: May 2021
Junior Member
Hi everyone!

I am working on python mqtt paho v1.5.1 for a connected device.

I connect the device to the broker with connect_async and start_loop.

When the machine does not succeed to publish the message ( mostly due to a connection problem ).
I disconnect the mqtt to the broker and restart a connection like I did the first time.
However, when the device is installed in some specific places where the internet connection is quite bad, it happens that the thread managing the connection-disconnection freezes and does not respond anymore. It is no more possible to publish mqtt message neither.
In this situation, the only possibility is to restart a thread managing mqtt problems but it is not a long term solution because at some point, it reaches the limit of thread on the device.

I have also seen that connect_async and start_loop would manage by itself connection-disconnection to the broker. so I wonder if what I am doing is the right way to do it?

Is it correct to disconnect-reconnect with connect_async and start_loop when we lost connection and we are no more able to publish or is it unadvised to do it manually and start_loop should manage it by its own?

Thank you in advance

Best regards
Re: Paho connection/disconnection freezing [message #1841205 is a reply to message #1841195] Thu, 06 May 2021 13:15 Go to previous messageGo to next message
Tom Vandenbussche is currently offline Tom VandenbusscheFriend
Messages: 3
Registered: May 2021
Junior Member
Due to the fact that connection and disconnection is calling _packet_queue() that has a mutex.
Should it be possible that the mutex will be infinitely blocked if loop_forever ( inside the thread used by start_loop ) tries to reconnect
and in a same time, we try to disconnect manually?
Re: Paho connection/disconnection freezing [message #1841206 is a reply to message #1841205] Thu, 06 May 2021 13:24 Go to previous messageGo to next message
Ian Craggs is currently offline Ian CraggsFriend
Messages: 83
Registered: March 2013
Member
The python client will reconnect automatically itself, or should do. It sounds like you might be confusing it by trying operations in parallel. The amount of time to detect a connection dying can be affected by the keepalive setting, so that shouldn't be too long, probably.

You shouldn't call loop_start more than once otherwise multiple threads are going to interact.

I found this little tutorial: http://www.steves-internet-guide.com/loop-python-mqtt-client/ It might be useful.
Re: Paho connection/disconnection freezing [message #1841211 is a reply to message #1841206] Thu, 06 May 2021 14:57 Go to previous message
Tom Vandenbussche is currently offline Tom VandenbusscheFriend
Messages: 3
Registered: May 2021
Junior Member
Thank you very much.

In the on_disconnect, we have a stop_loop() like in the tutorial you gave but, as you said, the keepalive could give the loop alive during enough time for the thread to keep running.
Indeed, I had the feeling that paho would be able to manage by its own the connection-disconnection but I wanted another advice.

Thank you again!
Previous Topic:Problem connecting mqtt for smart watch
Next Topic:AWS publish problem
Goto Forum:
  


Current Time: Fri May 03 11:44:45 GMT 2024

Powered by FUDForum. Page generated in 0.02915 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top