Django的停止工作与RuntimeError:填写()不折返 [英] Django stops working with RuntimeError: populate() isn't reentrant

查看:2876
本文介绍了Django的停止工作与RuntimeError:填写()不折返的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在开发部署WSGI Apache服务器上一个Django的web应用程序,一切都进展顺利。今天,我做出了一些细微的变化我的应用程序的 admin.py 企图定制内置的Django管理界面,并初步取得了语法错误(一个未关闭括号) 。这意味着,当我触摸 wsgi.py 并加载了code(我有我的WSGI虚拟主机在后台模式下运行),我的网站与内部更换服务器错误,因为WSGI停止当它击中的语法错误。

I've been developing a Django web application deployed on an Apache server with WSGI, and everything has been going smoothly. Today, I made some minor changes to my app's admin.py in an attempt to customize the build-in Django Admin interface, and initially made a syntax error (an unclosed parenthesis). This meant that when I touched wsgi.py and loaded the code (I have WSGI running in daemon mode on my virtual host), my website was replaced with an Internal Server Error because WSGI stopped when it hit the syntax error.

所以我固定的语法错误,经检查发现我没有任何更多的 manage.py检查,并触及 wsgi.py 重新部署。但我的网站仍然显示内部服务器错误!检查Apache日志,这是我所看到的:

So I fixed the syntax error, checked that I didn't have any more with manage.py check, and touched wsgi.py to redeploy. But my website still displays an Internal Server Error! Checking the Apache logs, this is what I see:

[Sun Nov 23 13:52:46 2014] [info] mod_wsgi (pid=19093): Create interpreter 'quotes.cs.cornell.edu|'.
[Sun Nov 23 13:52:46 2014] [info] mod_wsgi (pid=19093): Adding '/extra/www/html/quotes/quotes_django' to path.
[Sun Nov 23 13:52:46 2014] [info] mod_wsgi (pid=19093): Adding '/opt/rh/python27/root/usr/lib64/python2.7/site-
packages/' to path.
[Sun Nov 23 13:52:46 2014] [info] [client 128.84.33.19] mod_wsgi (pid=19093, process='quotes.cs.cornell.edu',
  application='quotes.cs.cornell.edu|'): Loading WSGI script '/extra/www/html/quotes/quotes_django/quotes_django/
wsgi.py'.
[Sun Nov 23 13:52:46 2014] [error] [client 128.84.33.19] mod_wsgi (pid=19093): Target WSGI script '/extra/www/html/
quotes/quotes_django/quotes_django/wsgi.py' cannot be loaded as Python module.
[Sun Nov 23 13:52:46 2014] [error] [client 128.84.33.19] mod_wsgi (pid=19093): Exception occurred processing WSGI
script '/extra/www/html/quotes/quotes_django/quotes_django/wsgi.py'.
[Sun Nov 23 13:52:46 2014] [error] [client 128.84.33.19] Traceback (most recent call last):
[Sun Nov 23 13:52:46 2014] [error] [client 128.84.33.19]   File "/extra/www/html/quotes/quotes_django/
quotes_django/wsgi.py", line 14, in <module>
[Sun Nov 23 13:52:46 2014] [error] [client 128.84.33.19]     application = get_wsgi_application()
[Sun Nov 23 13:52:46 2014] [error] [client 128.84.33.19]   File "/opt/rh/python27/root/usr/lib64/python2.7/site-
packages/django/core/wsgi.py", line 14, in get_wsgi_application
[Sun Nov 23 13:52:46 2014] [error] [client 128.84.33.19]     django.setup()
[Sun Nov 23 13:52:46 2014] [error] [client 128.84.33.19]   File "/opt/rh/python27/root/usr/lib64/python2.7/site-
packages/django/__init__.py", line 21, in setup
[Sun Nov 23 13:52:46 2014] [error] [client 128.84.33.19]     apps.populate(settings.INSTALLED_APPS)
[Sun Nov 23 13:52:46 2014] [error] [client 128.84.33.19]   File "/opt/rh/python27/root/usr/lib64/python2.7/site-
packages/django/apps/registry.py", line 115, in populate
[Sun Nov 23 13:52:46 2014] [error] [client 128.84.33.19]     app_config.ready()
[Sun Nov 23 13:52:46 2014] [error] [client 128.84.33.19]   File "/opt/rh/python27/root/usr/lib64/python2.7/site-
packages/django/contrib/admin/apps.py", line 22, in ready
[Sun Nov 23 13:52:46 2014] [error] [client 128.84.33.19]     self.module.autodiscover()
[Sun Nov 23 13:52:46 2014] [error] [client 128.84.33.19]   File "/opt/rh/python27/root/usr/lib64/python2.7/site-
packages/django/contrib/admin/__init__.py", line 23, in autodiscover
[Sun Nov 23 13:52:46 2014] [error] [client 128.84.33.19]     autodiscover_modules('admin', register_to=site)
[Sun Nov 23 13:52:46 2014] [error] [client 128.84.33.19]   File "/opt/rh/python27/root/usr/lib64/python2.7/site-
packages/django/utils/module_loading.py", line 74, in autodiscover_modules
[Sun Nov 23 13:52:46 2014] [error] [client 128.84.33.19]     import_module('%s.%s' % (app_config.name,         
module_to_search))
[Sun Nov 23 13:52:46 2014] [error] [client 128.84.33.19]   File "/usr/lib64/python2.7/importlib/__init__.py", line 
37, in import_module
[Sun Nov 23 13:52:46 2014] [error] [client 128.84.33.19]     __import__(name)
[Sun Nov 23 13:52:46 2014] [error] [client 128.84.33.19]   File "/extra/www/html/quotes/quotes_django/quotespage/
admin.py", line 25
[Sun Nov 23 13:52:46 2014] [error] [client 128.84.33.19]     approve_quotes.short_description = "Approve selected
quotes"
[Sun Nov 23 13:52:46 2014] [error] [client 128.84.33.19]                  ^
[Sun Nov 23 13:52:46 2014] [error] [client 128.84.33.19] SyntaxError: invalid syntax
[Sun Nov 23 13:53:36 2014] [info] [client 128.84.33.19] mod_wsgi (pid=19093, process='quotes.cs.cornell.edu',
  application='quotes.cs.cornell.edu|'): Loading WSGI script '/extra/www/html/quotes/quotes_django/quotes_django/
wsgi.py'.
[Sun Nov 23 13:53:36 2014] [error] [client 128.84.33.19] mod_wsgi (pid=19093): Target WSGI script '/extra/www/html/
quotes/quotes_django/quotes_django/wsgi.py' cannot be loaded as Python module.
[Sun Nov 23 13:53:36 2014] [error] [client 128.84.33.19] mod_wsgi (pid=19093): Exception occurred processing WSGI
script '/extra/www/html/quotes/quotes_django/quotes_django/wsgi.py'.
[Sun Nov 23 13:53:36 2014] [error] [client 128.84.33.19] Traceback (most recent call last):
[Sun Nov 23 13:53:36 2014] [error] [client 128.84.33.19]   File "/extra/www/html/quotes/quotes_django/         
quotes_django/wsgi.py", line 14, in <module>
[Sun Nov 23 13:53:36 2014] [error] [client 128.84.33.19]     application = get_wsgi_application()
[Sun Nov 23 13:53:36 2014] [error] [client 128.84.33.19]   File "/opt/rh/python27/root/usr/lib64/python2.7/site-
packages/django/core/wsgi.py", line 14, in get_wsgi_application
[Sun Nov 23 13:53:36 2014] [error] [client 128.84.33.19]     django.setup()
[Sun Nov 23 13:53:36 2014] [error] [client 128.84.33.19]   File "/opt/rh/python27/root/usr/lib64/python2.7/site-
packages/django/__init__.py", line 21, in setup
[Sun Nov 23 13:53:36 2014] [error] [client 128.84.33.19]     apps.populate(settings.INSTALLED_APPS)
[Sun Nov 23 13:53:36 2014] [error] [client 128.84.33.19]   File "/opt/rh/python27/root/usr/lib64/python2.7/site-
packages/django/apps/registry.py", line 78, in populate
[Sun Nov 23 13:53:36 2014] [error] [client 128.84.33.19]     raise RuntimeError("populate() isn't reentrant")
[Sun Nov 23 13:53:36 2014] [error] [client 128.84.33.19] RuntimeError: populate() isn't reentrant

第一系列错误显示WSGI没有因我的 admin.py 的语法错误。然而,第二系列错误似乎显示内部的Django一个错误:

The first series of errors shows WSGI failing due to the syntax error in my admin.py. However, the second series of errors seems to show an error internal to Django:

RuntimeError: populate() isn't reentrant

从抛出的

填充的方法 registry.py

谷歌搜索此错误消息返回的信息少得惊人,这一切没有从Django文档。很明显,如果你在你的 settings.py 命名一个应用程序两次它有时会发生,但我没有这样做。更重要的是,我并没有改变 settings.py ,因为那里的网站工作正常点 - 我改变了唯一的事情就是 admin.py

Googling this error message returns surprisingly little information, none of it from Django documentation. Apparently, it can sometimes happen if you name an app twice in your settings.py, but I'm not doing that. More importantly, I haven't changed settings.py since the point where the website was working fine -- the only thing I changed was admin.py.

我试图恢复我所做的所有更改,所以我所有的Python code是早在当网站被工作是国家 - 我仍然得到填写()不是个ŧ折返错误,当我试图让WSGI重装code!

I tried reverting all the changes I made, so all my Python code is back in the state it was when the website was working -- and I still get the populate() isn't reentrant error when I try to make WSGI reload the code!

我也试过在 settings.py 的INSTALLED_APPS部分注释出不同的应用程序,甚至只有django.contrib.staticfiles启用错误依然发生。古怪,我仍然得到错误,即使我注释掉的所有的应用程式 - !Django的抛出,即使它不加载任何应用程序错误

I've also tried commenting-out different apps in the INSTALLED_APPS section of settings.py, and even with only 'django.contrib.staticfiles' enabled the error still happens. Weirdly, I still get the error even if I comment out all the apps -- Django throws the error even when it isn't loading any apps!

有谁知道这是怎么回事?或者没有更好的办法,我调试这个错误,因为在Apache日志中回溯是pretty无益?

Does anyone know what's going on here? Or any better way for me to debug this error, since the traceback in the Apache log is pretty unhelpful?

注:我使用的Django 1.7,Apache 2.2的,和Python 2.7。

Notes: I'm using Django 1.7, Apache 2.2, and Python 2.7.

推荐答案

我的服务器的管理员重新启动Apache和奇迹般地解决了这个问题。而不会引起填充加载()完全相同的Python文件不能重返进入。我甚至尝试加载另一个文件有语法错误,那么修复它,服务器能够加载新的文件并没有问题正确运行。

My server's administrator restarted Apache, and that magically fixed this problem. The exact same Python files loaded without causing populate() isn't reentrant. I even tried loading another file with a syntax error, then fixing it, and the server was able to load the new file and run correctly with no problems.

我仍然不知道发生了什么事情错了,但我这标志着作为回答,因为这个问题已经一去不复返了。 (好吧,我将其标记为尽快回答的计算器可以让我接受我自己的答案。)

I still don't know what was going wrong, but I'm marking this as answered since the problem is gone. (Well, I'll mark it as answered as soon as StackOverflow allows me to accept my own answer.)

更新:继续得到这个错误,当我不小心上传的Python语法错误后,我想出了一个解决办法,这比重启动Apache更容易。当WSGI开始投掷填写()不能重返进入的错误,我代替我的Django项目的 wsgi.py 与此简单的功能:

Update: After continuing to get this error when I accidentally upload Python with syntax errors, I figured out a workaround that's easier than restarting Apache. When WSGI starts throwing the populate() isn't reentrant error, I replace my Django project's wsgi.py with this simple function:

def application(environ, start_response):
    if environ['mod_wsgi.process_group'] != '': 
        import signal
        os.kill(os.getpid(), signal.SIGINT)
    return ["killed"]

然后我重装我的网站,和WSGI守护进程重新启动(我可以通过查看Apache日志告知,即使该网站仍显示相同的500错误)。

Then I reload my website, and the WSGI daemon process restarts (which I can tell by looking at the Apache log, even though the website still displays the same 500 error).

如果我再改 wsgi.py 恢复正常并重新加载,WSGI成功地拿起我的code没有抛出填写()不能重返进入(假设我已经没有语法错误这段时间)。所以阿帕奇的全部并不需要重新启动,只是WSGI的过程,我能做到这一点没有root权限。

If I then change wsgi.py back to normal and reload again, WSGI successfully picks up my code without throwing populate() isn't reentrant (assuming I have no syntax errors this time). So the entirety of Apache doesn't need to restart, just the WSGI process, and I can do that without root privileges.

这篇关于Django的停止工作与RuntimeError:填写()不折返的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆