Skip to content

Commit f13cc67

Browse files
author
Your Name
committed
settimeout
1 parent 98f8a7e commit f13cc67

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

micropython/umqtt.simple/umqtt/simple.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,16 @@ def set_last_will(self, topic, msg, retain=False, qos=0):
6060
self.lw_qos = qos
6161
self.lw_retain = retain
6262

63+
def settimeout(self, value):
64+
'''Blocking socket can cause non determinstic hang incase of n/w failure.
65+
Hence, by setting timeout, application programmer can get exception in case of failure.
66+
This enable him/her to take appropriate action like restarting the task etc.
67+
This works for async apps too.
68+
'''
69+
self._sock.settimeout(value)
70+
6371
def connect(self, clean_session=True):
64-
self.sock = socket.socket()
72+
self._sock = self.sock = socket.socket()
6573
addr = socket.getaddrinfo(self.server, self.port)[0][-1]
6674
self.sock.connect(addr)
6775
if self.ssl:

0 commit comments

Comments
 (0)