@@ -834,14 +834,16 @@ def reconnect(self, resub_topics=True):
834834 feed = subscribed_topics .pop ()
835835 self .subscribe (feed )
836836
837- def loop (self , timeout = 1 ):
837+ def loop (self , timeout = 0 ):
838+ # pylint: disable = too-many-return-statements
838839 """Non-blocking message loop. Use this method to
839840 check incoming subscription messages.
840841 Returns response codes of any messages received.
841842
842843 :param int timeout: Socket timeout, in seconds.
843844
844845 """
846+
845847 if self ._timestamp == 0 :
846848 self ._timestamp = time .monotonic ()
847849 current_time = time .monotonic ()
@@ -854,11 +856,28 @@ def loop(self, timeout=1):
854856 )
855857 rcs = self .ping ()
856858 return rcs
859+
860+ stamp = time .monotonic ()
857861 self ._sock .settimeout (timeout )
858- rc = self ._wait_for_msg ()
859- return [rc ] if rc else None
862+ rcs = []
863+
864+ while True :
865+ rc = self ._wait_for_msg (timeout )
866+ if rc is None :
867+ break
868+ if time .monotonic () - stamp > self ._recv_timeout :
869+ if self .logger is not None :
870+ self .logger .debug (
871+ f"Loop timed out, message queue not empty after { self ._recv_timeout } s"
872+ )
873+ break
874+ rcs .append (rc )
875+
876+ return rcs if rcs else None
860877
861878 def _wait_for_msg (self , timeout = 0.1 ):
879+ # pylint: disable = too-many-return-statements
880+
862881 """Reads and processes network events."""
863882 # CPython socket module contains a timeout attribute
864883 if hasattr (self ._socket_pool , "timeout" ):
0 commit comments