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

2 投票
1 回答
710 浏览
提问于 2025-04-16 23:16

我在Ubuntu 10.10(64位)上运行Django 1.3和Python 2.6,并使用uWSGI(0.9.8)。不过,有时候我会在uwsgi.log里看到一些奇怪的日志,报告说'getattr'和'isinstance'没有定义。但它们不是Python的内置函数吗?为什么Django找不到它们呢?这种情况不常发生,通常是在流量较低或者uWSGI服务器重启的时候,而在流量大的时候,服务器运行一段时间后就会经常出现。

我确定我的Django应用没有问题,但我不确定这是Django、uWSGI还是Python 2.6的bug。

更新:最新版本的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

1 个回答

1

你能试试最新的版本吗?看起来像是一个引用计数的错误,这个问题应该在0.9.9-dev版本中修复了。

如果你能确认这个版本解决了你的问题,我会发布一个更新的版本,只包含这个修复。

非常感谢你的反馈!

撰写回答