def autoreconnect_retry(func, retries=3):
"""Decorating checking connection to the database."""
def db_op_wrapper(*args, **kwargs):
"""Decorator wrapper"""
tries = 0
while tries < retries:
try:
return func(*args, **kwargs)
except AutoReconnect:
tries += 1
raise Exception(
"Couldn't connect to the database, even after %d retries" % retries)
return db_op_wrapper
评论列表
文章目录