@@ -145,13 +145,15 @@ def __init__(
145
145
socket_pool = None ,
146
146
ssl_context = None ,
147
147
use_binary_mode = False ,
148
+ socket_timeout = 1 ,
148
149
):
149
150
150
151
self ._socket_pool = socket_pool
151
152
self ._ssl_context = ssl_context
152
153
self ._sock = None
153
154
self ._backwards_compatible_sock = False
154
155
self ._use_binary_mode = use_binary_mode
156
+ self ._socket_timeout = socket_timeout
155
157
156
158
self .keep_alive = keep_alive
157
159
self ._user_data = None
@@ -209,12 +211,12 @@ def __init__(
209
211
self .on_unsubscribe = None
210
212
211
213
# pylint: disable=too-many-branches
212
- def _get_connect_socket (self , host , port , * , timeout = 1 ):
214
+ def _get_connect_socket (self , host , port , * , timeout ):
213
215
"""Obtains a new socket and connects to a broker.
214
216
215
217
:param str host: Desired broker hostname
216
218
:param int port: Desired broker port
217
- :param int timeout: Desired socket timeout
219
+ :param int timeout: Desired socket timeout in seconds
218
220
"""
219
221
# For reconnections - check if we're using a socket already and close it
220
222
if self ._sock :
@@ -444,7 +446,7 @@ def connect(self, clean_session=True, host=None, port=None, keep_alive=None):
444
446
self .logger .debug ("Attempting to establish MQTT connection..." )
445
447
446
448
# Get a new socket
447
- self ._sock = self ._get_connect_socket (self .broker , self .port )
449
+ self ._sock = self ._get_connect_socket (self .broker , self .port , timeout = self . _socket_timeout )
448
450
449
451
# Fixed Header
450
452
fixed_header = bytearray ([0x10 ])
0 commit comments