错误324 空响应 - AttributeError: 'NoneType'对象没有属性'select
我正在使用 Python 2.7.3 和 Django 1.5.8。我想要在新安装的环境中看到“它工作了”。但是在 Chrome 中我遇到了 错误 324:
Unable to load the webpage because the server sent no data.
Error code: ERR_EMPTY_RESPONSE
当我关闭服务器时,出现了以下错误信息:
0 errors found
June 02, 2014 - 06:39:55
Django version 1.5.8, using settings 'fed1.settings.dev'
Development server is running at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
♥Unhandled exception in thread started by <bound method Command.inner_run of <django.contrib.staticfiles.management.commands.runserver.Command object at 0x19fd950>>
Traceback (most recent call last):
File "/home/vagrant/fed1-venv/local/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 115, in inner_run
ipv6=self.use_ipv6, threading=threading)
File "/home/vagrant/fed1-venv/local/lib/python2.7/site-packages/django/core/servers/basehttp.py", line 186, in run
httpd.serve_forever()
File "/usr/lib/python2.7/SocketServer.py", line 225, in serve_forever
r, w, e = select.select([self], [], [], poll_interval)
AttributeError: 'NoneType' object has no attribute 'select'
我之前看到过,有人说这个错误和 Python 2.5.1 有关,在 2.5.2 版本中解决了。但现在我找不到那个信息了。可能是在 code.djangoproject.com 上,但也许这不是同样的问题。
我看到有个帖子提到过 如何在重启 django runserver 时“清理”端口,有人说服务器已经在运行,所以我尝试了那个解决方案:
(fed1-venv)vagrant@precise64:/vagrant/fed1$ ps aux | grep -i manage
vagrant 10113 0.0 0.2 11676 940 pts/0 S+ 14:57 0:00 grep --color=auto -i manage
然后我试着把它调到前台去关闭,但:
(fed1-venv)vagrant@precise64:/vagrant/fed1$ fg
bash: fg: current: no such job
所以这也不是我的问题。
还有一个帖子 Django - 使用静态文件时的奇怪行为 也有类似的错误,通过 URL 模式解决了——但我还没到那一步。我只是想要看到‘它工作了’。我看到大多数问这个错误的人,网站已经在正常运行了。
我查看了 socketserver.py
,但我还不够专业,无法理解里面的内容。
1 个回答
别担心那个异常,你可以放心地忽略它。你的服务器已经退出了,虽然有点乱。
在关闭时,Python会清理全局变量,以防止循环依赖导致无法完成清理。它通过将这些变量重新绑定为 None
来实现。
你是通过键盘中断(CTRL-C)来关闭服务器的,这会触发清理过程。与此同时, serve_forever
线程还在运行它的套接字轮询循环,但 SocketServer
模块中的 select
全局变量已经被重新绑定了。因此,查找 select.select()
时就失败了。
如果这让你感到困扰,可以升级到 Python 3.4。这个版本在大多数情况下不再将全局变量设置为 None
,具体可以参考 安全对象清理; 还可以查看 PEP 442。
至于你提到的 Chrome 错误代码和其他问题,某个东西 已经占用了你想用来运行 Django 的端口。这和你看到的 select.select()
调用的异常是完全不同的问题。可能是其他软件占用了那个端口,而这个软件不响应 HTTP 请求(导致 Chrome 报错)。
你可以查看 如何确定哪个进程占用了某个端口(Linux)或 在 Mac OS X 上谁在监听某个 TCP 端口?(Mac)来解决这个问题。