connection timeout
Is there any way of setting a timeout for the client.connect method?
I want to do the same thing. I'm having a connection timeout error as well when I try to establish connection over TLS. I initially thought the networks was slow but OpenVPN works on the same network. How can I modify the timeout value when connecting?
Hello guys, from what I can understand here you can just set the timeout by setting the keepalive variable. Give it a shot and see what comes of it.
For me this doesn't work. The problem is that inside reconnect method there is a call to socket.create_connection. This function has a default the default timeout "_GLOBAL_DEFAULT_TIMEOUT". The solution for me is to modify socket.create_connection((self._host, self._port)) call with socket.create_connection((self._host, self._port), timeout=self._keepalive)
This issue hasn't been resolved.
As a workaround you can set default socket timeout and then use client.connect.
import socket
socket.setdefaulttimeout(timeout)
The default timeout for socket doesn't work, using paho.mqtt.publish.single as it probably get's overwritten by paho in the process.
Changes have been made since this issue was raised; you can now use:
mqtt_client = mqtt.Client()
mqtt_client._connect_timeout = 1.0
I believe that this addresses the original issue so am going to close this. If you are still having problems then please raise a new issue (but please include as much information as possible including code/logs).