使用 uWSGI 时,Django 中的内置 Python 函数出现 NameError

发布于 2024-11-29 02:31:11 字数 2694 浏览 1 评论 0原文

我正在 Ubuntu 10.10(64 位)上使用 uWSGI(0.9.8)运行 Django 1.3 + Python 2.6。 但是,有时我会在 uwsgi.log 中发现一些奇怪的日志,报告“getattr”、“isinstance”未定义。但它们不是Python的内置函数吗?为什么 Django 找不到它们?当 uwsgi 服务器重新启动时流量较低时,这种情况不会经常发生,而当流量较大且服务器运行很短一段时间时,这种情况会经常出现。

我确信我的 django 应用程序没有任何问题,但我不确定这是否是 Django、uWSGI 甚至 Python 2.6 中的错误。

更新:最新版本的uWSGI似乎不再有这个。

详细日志:

Error in sys.excepthook:
 Traceback (most recent call last):
   File "/usr/lib/python2.6/dist-packages/apport_python_hook.py", line 48,  in apport_excepthook
     if not enabled():
   File "/usr/lib/python2.6/dist-packages/apport_python_hook.py", line 24,  in enabled
     return re.search('^\s*enabled\s*=\s*0\s*$', conf, re.M) is None
   File "/usr/lib/python2.6/re.py", line 142, in search
     return _compile(pattern, flags).search(string)
   File "/usr/lib/python2.6/re.py", line 236, in _compile
     if isinstance(pattern, _pattern_type):
 NameError: global name 'isinstance' is not defined

 Original exception was:
 Traceback (most recent call last):
   File "/usr/local/lib/python2.6/dist-
 packages/django/core/handlers/wsgi.py", line 258, in __call__
     set_script_prefix(base.get_script_name(environ))
   File "/usr/local/lib/python2.6/dist-
 packages/django/core/handlers/base.py", line 239, in get_script_name
     if settings.FORCE_SCRIPT_NAME is not None:
   File "/usr/local/lib/python2.6/dist-
 packages/django/utils/functional.py", line 277, in __getattr__
     return getattr(self._wrapped, name)
 NameError: global name 'getattr' is not defined  Traceback (most recent call last):
   File "/usr/local/lib/python2.6/dist-
 packages/django/core/handlers/wsgi.py", line 258, in __call__
     set_script_prefix(base.get_script_name(environ))
   File "/usr/local/lib/python2.6/dist-
 packages/django/core/handlers/base.py", line 252, in get_script_name
     return force_unicode(environ.get('SCRIPT_NAME', u''))
   File "/usr/local/lib/python2.6/dist-packages/django/utils/encoding.py",
 line 64, in force_unicode
     if isinstance(s, unicode):
 NameError: global name 'isinstance' is not defined  Error in sys.excepthook:
 Traceback (most recent call last):
   File "/usr/lib/python2.6/dist-packages/apport_python_hook.py", line 48,  in apport_excepthook
     if not enabled():
   File "/usr/lib/python2.6/dist-packages/apport_python_hook.py", line 24,  in enabled
     return re.search('^\s*enabled\s*=\s*0\s*$', conf, re.M) is None
   File "/usr/lib/python2.6/re.py", line 142, in search
     return _compile(pattern, flags).search(string)
   File "/usr/lib/python2.6/re.py", line 236, in _compile
     if isinstance(pattern, _pattern_type):
 NameError: global name 'isinstance' is not defined

I'm running Django 1.3 + Python 2.6 on Ubuntu 10.10 (64bit) with uWSGI (0.9.8).
However, occasionally I can find some strange logs in uwsgi.log, reporting that 'getattr', 'isinstance' is not defined. But aren't they Python's built-in functions? Why Django unable to find them? This happens not often when traffic is low of when the uwsgi server restarts, and appear much often when the traffic is large and the server runs for a short while.

I'm sure that there is nothing wrong with my django application, but I'm not sure if this is a bug in Django, uWSGI or even Python 2.6.

UPDATE: The latest version of uWSGI doesn't seemed to have this again.

Detail log:

Error in sys.excepthook:
 Traceback (most recent call last):
   File "/usr/lib/python2.6/dist-packages/apport_python_hook.py", line 48,  in apport_excepthook
     if not enabled():
   File "/usr/lib/python2.6/dist-packages/apport_python_hook.py", line 24,  in enabled
     return re.search('^\s*enabled\s*=\s*0\s*
, conf, re.M) is None
   File "/usr/lib/python2.6/re.py", line 142, in search
     return _compile(pattern, flags).search(string)
   File "/usr/lib/python2.6/re.py", line 236, in _compile
     if isinstance(pattern, _pattern_type):
 NameError: global name 'isinstance' is not defined

 Original exception was:
 Traceback (most recent call last):
   File "/usr/local/lib/python2.6/dist-
 packages/django/core/handlers/wsgi.py", line 258, in __call__
     set_script_prefix(base.get_script_name(environ))
   File "/usr/local/lib/python2.6/dist-
 packages/django/core/handlers/base.py", line 239, in get_script_name
     if settings.FORCE_SCRIPT_NAME is not None:
   File "/usr/local/lib/python2.6/dist-
 packages/django/utils/functional.py", line 277, in __getattr__
     return getattr(self._wrapped, name)
 NameError: global name 'getattr' is not defined  Traceback (most recent call last):
   File "/usr/local/lib/python2.6/dist-
 packages/django/core/handlers/wsgi.py", line 258, in __call__
     set_script_prefix(base.get_script_name(environ))
   File "/usr/local/lib/python2.6/dist-
 packages/django/core/handlers/base.py", line 252, in get_script_name
     return force_unicode(environ.get('SCRIPT_NAME', u''))
   File "/usr/local/lib/python2.6/dist-packages/django/utils/encoding.py",
 line 64, in force_unicode
     if isinstance(s, unicode):
 NameError: global name 'isinstance' is not defined  Error in sys.excepthook:
 Traceback (most recent call last):
   File "/usr/lib/python2.6/dist-packages/apport_python_hook.py", line 48,  in apport_excepthook
     if not enabled():
   File "/usr/lib/python2.6/dist-packages/apport_python_hook.py", line 24,  in enabled
     return re.search('^\s*enabled\s*=\s*0\s*
, conf, re.M) is None
   File "/usr/lib/python2.6/re.py", line 142, in search
     return _compile(pattern, flags).search(string)
   File "/usr/lib/python2.6/re.py", line 236, in _compile
     if isinstance(pattern, _pattern_type):
 NameError: global name 'isinstance' is not defined

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情归归情 2024-12-06 02:31:11

您可以尝试一下最新的提示吗?它看起来像一个引用计数错误,应该在 0.9.9-dev 中修复

如果您可以确认它解决了您的问题,我将发布一个仅应用此修复的更新版本。

非常感谢您的报告

Can you try with the latest tip ? It looks like a reference counting bug that should be fixed in 0.9.9-dev

If you can confirm it solves your problem i will release an updated release with only this fix applied.

Many thanks for the report

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文