当前位置: 首页>>代码示例>>Python>>正文


Python backends.DatabaseError方法代码示例

本文整理汇总了Python中django.db.backends.DatabaseError方法的典型用法代码示例。如果您正苦于以下问题:Python backends.DatabaseError方法的具体用法?Python backends.DatabaseError怎么用?Python backends.DatabaseError使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.db.backends的用法示例。


在下文中一共展示了backends.DatabaseError方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _validate_thread_sharing

# 需要导入模块: from django.db import backends [as 别名]
# 或者: from django.db.backends import DatabaseError [as 别名]
def _validate_thread_sharing(self):
            if (not self.allow_thread_sharing
                and self._thread_ident != _get_ident()):
                    raise DatabaseError("DatabaseWrapper objects created in a "
                        "thread can only be used in that same thread. The object "
                        "with alias '%s' was created in thread id %s and this is "
                        "thread id %s."
                        % (self.alias, self._thread_ident, _get_ident())) 
开发者ID:RoseOu,项目名称:flasky,代码行数:10,代码来源:run_gunicorn.py

示例2: patch_thread_ident

# 需要导入模块: from django.db import backends [as 别名]
# 或者: from django.db.backends import DatabaseError [as 别名]
def patch_thread_ident():
    # monkey patch django.
    # This patch make sure that we use real threads to get the ident which
    # is going to happen if we are using gevent or eventlet.
    # -- patch taken from gunicorn
    if getattr(patch_thread_ident, 'called', False):
        return
    try:
        from django.db.backends import BaseDatabaseWrapper, DatabaseError

        if 'validate_thread_sharing' in BaseDatabaseWrapper.__dict__:
            import thread
            _get_ident = thread.get_ident

            __old__init__ = BaseDatabaseWrapper.__init__

            def _init(self, *args, **kwargs):
                __old__init__(self, *args, **kwargs)
                self._thread_ident = _get_ident()

            def _validate_thread_sharing(self):
                if (not self.allow_thread_sharing
                        and self._thread_ident != _get_ident()):
                    raise DatabaseError(
                        DB_SHARED_THREAD % (
                            self.alias, self._thread_ident, _get_ident()),
                    )

            BaseDatabaseWrapper.__init__ = _init
            BaseDatabaseWrapper.validate_thread_sharing = \
                _validate_thread_sharing

        patch_thread_ident.called = True
    except ImportError:
        pass 
开发者ID:NetEaseGame,项目名称:Sentry,代码行数:37,代码来源:command.py


注:本文中的django.db.backends.DatabaseError方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。