def __call__(self, *args, **kwargs):
""" Call the method and handle the AutoReconnect exception gracefully """
start_time = time.time()
for attempt in count():
try:
return self._method(*args, **kwargs)
except AutoReconnect:
duration = time.time() - start_time
if duration >= WAIT_TIME:
break
logger.warning(
'Reconnecting to MongoDB, attempt {} ({:.3f} seconds elapsed)'.
format(attempt, duration))
time.sleep(self.calc_sleep(attempt))
return self._method(*args, **kwargs)
评论列表
文章目录