@@ -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: timeout to wait for a message , in seconds.
988987
989988 """
990989
@@ -1002,23 +1001,21 @@ 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 :
1007+ rc = self ._wait_for_msg ()
1008+ if rc is not None :
1009+ rcs . append ( rc )
1010+ if time .monotonic () - stamp > timeout :
10131011 self .logger .debug (
1014- f"Loop timed out, message queue not empty after { self . _recv_timeout } s "
1012+ f"Loop timed out, message queue empty after { timeout } seconds "
10151013 )
10161014 break
1017- rcs .append (rc )
10181015
10191016 return rcs if rcs else None
10201017
1021- def _wait_for_msg (self , timeout : float = 0.1 ) -> Optional [int ]:
1018+ def _wait_for_msg (self ) -> Optional [int ]:
10221019 # pylint: disable = too-many-return-statements
10231020
10241021 """Reads and processes network events.
@@ -1039,8 +1036,6 @@ def _wait_for_msg(self, timeout: float = 0.1) -> Optional[int]:
10391036 return None
10401037 raise MMQTTException from error
10411038
1042- # Block while we parse the rest of the response
1043- self ._sock .settimeout (timeout )
10441039 if res in [None , b"" , b"\x00 " ]:
10451040 # If we get here, it means that there is nothing to be received
10461041 return None
0 commit comments