def reset_connection_on_interface_error(func):
"""Decorates function to reset the current thread's Django database
connection on exceptions that appear to come from connection resets.
"""
def _reset(*args, **kwargs):
try:
return func(*args, **kwargs)
except (InterfaceError, OperationalError,
DjangoInterfaceError, DjangoOperationalError) as error:
thread = threading.current_thread()
_logger.warning("it appears this thread's database connection was "
"dropped, resetting it now - you may see further "
"errors about this until the situation is fully "
"resolved for all threads "
"(this thread is '%s', error was '%s')",
thread.name, error)
django.db.connection.connection = None
raise ResetDBConnectionError("The database connection was reset",
error)
return wraps(func)(_reset)
评论列表
文章目录