Skip to content

Commit feb8c2e

Browse files
committed
added a timeout and syntax better matching ping()
1 parent dde29b5 commit feb8c2e

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

adafruit_minimqtt/adafruit_minimqtt.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -854,17 +854,24 @@ def loop(self, timeout=1):
854854
)
855855
rcs = self.ping()
856856
return rcs
857-
self._sock.settimeout(timeout)
858857

859-
responses = []
858+
stamp = time.monotonic()
859+
self._sock.settimeout(timeout)
860+
rcs = []
860861
while True:
861862
rc = self._wait_for_msg()
862863
if rc == None:
863864
break
865+
if time.monotonic() - stamp > self._recv_timeout:
866+
if self.logger is not None:
867+
self.logger.debug(
868+
f"Loop timed out, message queue not empty after {self._recv_timeout}s"
869+
)
870+
break
864871
else:
865-
responses.append(rc)
872+
rcs.append(rc)
866873

867-
return responses if responses else None
874+
return rcs if rcs else None
868875

869876

870877
def _wait_for_msg(self, timeout=0.1):

0 commit comments

Comments
 (0)