@@ -411,7 +411,8 @@ def listen_for_events(self, timeout_ms=30000):
411
411
"""
412
412
self ._sync (timeout_ms )
413
413
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 ):
415
416
""" Keep listening for events forever.
416
417
417
418
Args:
@@ -420,21 +421,23 @@ def listen_forever(self, timeout_ms=30000, exception_handler=None):
420
421
exception_handler (func(exception)): Optional exception handler
421
422
function which can be used to handle exceptions in the caller
422
423
thread.
424
+ aad_sync_timeout (int): Base time to wait after an error before
425
+ retrying. Will be increased according to exponential backoff.
423
426
"""
424
- bad_sync_timeout = 5000
427
+ _bad_sync_timeout = bad_sync_timeout
425
428
self .should_listen = True
426
429
while (self .should_listen ):
427
430
try :
428
431
self ._sync (timeout_ms )
429
- bad_sync_timeout = 5
432
+ _bad_sync_timeout = bad_sync_timeout
430
433
except MatrixRequestError as e :
431
434
logger .warning ("A MatrixRequestError occured during sync." )
432
435
if e .code >= 500 :
433
436
logger .warning ("Problem occured serverside. Waiting %i seconds" ,
434
437
bad_sync_timeout )
435
438
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 )
438
441
elif exception_handler is not None :
439
442
exception_handler (e )
440
443
else :
0 commit comments