@@ -411,7 +411,8 @@ def listen_for_events(self, timeout_ms=30000):
411411 """
412412 self ._sync (timeout_ms )
413413
414- def listen_forever (self , timeout_ms = 30000 , exception_handler = None ):
414+ def listen_forever (self , timeout_ms = 30000 , exception_handler = None ,
415+ bad_sync_timeout = 5 ):
415416 """ Keep listening for events forever.
416417
417418 Args:
@@ -420,21 +421,23 @@ def listen_forever(self, timeout_ms=30000, exception_handler=None):
420421 exception_handler (func(exception)): Optional exception handler
421422 function which can be used to handle exceptions in the caller
422423 thread.
424+ aad_sync_timeout (int): Base time to wait after an error before
425+ retrying. Will be increased according to exponential backoff.
423426 """
424- bad_sync_timeout = 5000
427+ _bad_sync_timeout = bad_sync_timeout
425428 self .should_listen = True
426429 while (self .should_listen ):
427430 try :
428431 self ._sync (timeout_ms )
429- bad_sync_timeout = 5
432+ _bad_sync_timeout = bad_sync_timeout
430433 except MatrixRequestError as e :
431434 logger .warning ("A MatrixRequestError occured during sync." )
432435 if e .code >= 500 :
433436 logger .warning ("Problem occured serverside. Waiting %i seconds" ,
434437 bad_sync_timeout )
435438 sleep (bad_sync_timeout )
436- bad_sync_timeout = min (bad_sync_timeout * 2 ,
437- self .bad_sync_timeout_limit )
439+ _bad_sync_timeout = min (_bad_sync_timeout * 2 ,
440+ self .bad_sync_timeout_limit )
438441 elif exception_handler is not None :
439442 exception_handler (e )
440443 else :
0 commit comments