@@ -980,11 +980,10 @@ def reconnect(self, resub_topics: bool = True) -> int:
980980
981981 def loop (self , timeout : float = 0 ) -> Optional [list [int ]]:
982982 # pylint: disable = too-many-return-statements
983- """Non-blocking message loop. Use this method to
984- check incoming subscription messages.
985- Returns response codes of any messages received.
983+ """Non-blocking message loop. Use this method to check for incoming messages.
984+ Returns list of response codes of any messages received or None.
986985
987- :param float timeout: Socket timeout, in seconds.
986+ :param float timeout: return after this timeout, in seconds.
988987
989988 """
990989
@@ -1002,23 +1001,19 @@ def loop(self, timeout: float = 0) -> Optional[list[int]]:
10021001 return rcs
10031002
10041003 stamp = time .monotonic ()
1005- self ._sock .settimeout (timeout )
10061004 rcs = []
10071005
10081006 while True :
1009- rc = self ._wait_for_msg (timeout )
1010- if rc is None :
1011- break
1012- if time .monotonic () - stamp > self ._recv_timeout :
1013- self .logger .debug (
1014- f"Loop timed out, message queue not empty after { self ._recv_timeout } s"
1015- )
1007+ rc = self ._wait_for_msg ()
1008+ if rc is not None :
1009+ rcs .append (rc )
1010+ if time .monotonic () - stamp > timeout :
1011+ self .logger .debug (f"Loop timed out after { timeout } seconds" )
10161012 break
1017- rcs .append (rc )
10181013
10191014 return rcs if rcs else None
10201015
1021- def _wait_for_msg (self , timeout : float = 0.1 ) -> Optional [int ]:
1016+ def _wait_for_msg (self ) -> Optional [int ]:
10221017 # pylint: disable = too-many-return-statements
10231018
10241019 """Reads and processes network events.
@@ -1039,8 +1034,6 @@ def _wait_for_msg(self, timeout: float = 0.1) -> Optional[int]:
10391034 return None
10401035 raise MMQTTException from error
10411036
1042- # Block while we parse the rest of the response
1043- self ._sock .settimeout (timeout )
10441037 if res in [None , b"" , b"\x00 " ]:
10451038 # If we get here, it means that there is nothing to be received
10461039 return None
0 commit comments