db.py 文件源码

python
阅读 51 收藏 0 点赞 0 评论 0

项目:nav 作者: UNINETT 项目源码 文件源码
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)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号