code: def listen_forever(self, timeout_ms=30000, exception_handler=None,
                         bad_sync_timeout=5):
          
          _bad_sync_timeout = bad_sync_timeout
          self.should_listen = True
          while (self.should_listen):
              try:
                  self._sync(timeout_ms)
                  _bad_sync_timeout = bad_sync_timeout
              # TODO: we should also handle MatrixHttpLibError for retry in case no response
              except MatrixRequestError as e:
                  logger.warning("A MatrixRequestError occured during sync.")
                  if e.code >= 500:
                      logger.warning("Problem occured serverside. Waiting %i seconds",
                                     bad_sync_timeout)
                      sleep(bad_sync_timeout)
                      _bad_sync_timeout = min(_bad_sync_timeout * 2,
                                              self.bad_sync_timeout_limit)
                  elif exception_handler is not None:
                      exception_handler(e)
                  else:
                      raise
              except Exception as e:
                  logger.exception("Exception thrown during sync")
                  if exception_handler is not None:
                      exception_handler(e)
                  else:
                      raise
docs: Keep listening for events forever.
  
          Args:
              timeout_ms (int): How long to poll the Home Server for before
                 retrying.
              exception_handler (func(exception)): Optional exception handler
                 function which can be used to handle exceptions in the caller
                 thread.
              bad_sync_timeout (int): Base time to wait after an error before
                  retrying. Will be increased according to exponential backoff.