Django停止使用RuntimeError:populate()不可重入

问题描述 投票:82回答:31

我一直在使用WSGI开发部署在Apache服务器上的Django Web应用程序,一切都进展顺利。今天,我对我的应用程序的admin.py进行了一些小的更改,试图自定义内置的Django Admin界面,并且最初产生了语法错误(一个未闭合的括号)。这意味着当我触摸wsgi.py并加载代码(我在我的虚拟主机上以守护进程模式运行WSGI)时,我的网站被替换为内部服务器错误,因为WSGI在遇到语法错误时停止了。

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

[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

由于我的admin.py中的语法错误,第一系列错误显示WSGI失败。但是,第二系列错误似乎表明Django内部存在错误:

RuntimeError: populate() isn't reentrant

populateregistry.py方法抛出。

谷歌搜索此错误消息令人惊讶的回报很少,没有来自Django文档。显然,如果你在settings.py中为应用程序命名两次,有时会发生这种情况,但我不这样做。更重要的是,自从网站工作正常以来,我没有改变settings.py - 我唯一改变的是admin.py

我尝试恢复我所做的所有更改,所以我的所有Python代码都恢复到网站工作时的状态 - 当我尝试使WSGI重新加载代码时,我仍然得到populate() isn't reentrant错误!

我也尝试在settings.py的INSTALLED_APPS部分中评论出不同的应用程序,即使只启用了“django.contrib.staticfiles”,错误仍然会发生。奇怪的是,即使我注释掉所有应用程序,我仍然会收到错误 - 即使没有加载任何应用程序,Django也会抛出错误!

有谁知道这里发生了什么?或者我有更好的方法来调试此错误,因为Apache日志中的回溯非常无益吗?

注意:我正在使用Django 1.7,Apache 2.2和Python 2.7。

django apache mod-wsgi django-wsgi
31个回答
56
投票

我的服务器管理员重新启动了Apache,这神奇地解决了这个问题。完全相同的Python文件加载而不会导致populate() isn't reentrant。我甚至尝试加载另一个语法错误的文件,然后修复它,服务器能够加载新文件并正确运行没有问题。

我仍然不知道出了什么问题,但是由于问题已经消失,我将此标记为已回答。 (好吧,一旦StackOverflow允许我接受我自己的答案,我会将其标记为已回答。)

更新:在我意外上传带有语法错误的Python后继续出现此错误后,我想出了一个比重启Apache更容易的解决方法。当WSGI开始抛出populate() isn't reentrant错误时,我用这个简单的函数替换我的Django项目的wsgi.py

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

然后我重新加载我的网站,并重新启动WSGI守护进程(我可以通过查看Apache日志来判断,即使网站仍然显示相同的500错误)。

如果我然后将wsgi.py恢复正常并重新加载,WSGI成功地获取我的代码而不抛出populate() isn't reentrant(假设这次我没有语法错误)。所以整个Apache不需要重启,只需要重启WSGI进程,我可以在没有root权限的情况下完成。


1
投票

我刚遇到同样的问题所以我开始环顾四周。

现在我已经开始工作了,所以我想我应该和你们分享吧!

我所做的只是重新做chown user:group /to/path -Rchmod 770 /to/path -R而且它奏效了。


1
投票

设置:Ubuntu 14.04,Django 1.10,Python 3.5(在virtualenv中)。

我没有运气就尝试了很多这些解决方案,但后来我注意到Apache错误日志在我的情况下包含两个不同的错误。当有人试图访问某个页面时会发生这种情况,另一个会在启动时发生。我错过了启动一个,因为我经常尝试刷新页面几次,因此只看到访问错误重复了几次。

然后我搜索了启动错误的解决方案,以及this question worked for me的解决方案。简而言之,它涉及以迂回方式更新mod_wsgi包。

几个月来我一直收到关于mod_wsgi版本不匹配的警告,但突然间它导致了Apache错误500。对我没有任何意义。

我的猜测是,这个RuntimeError: populate() isn't reentrant错误通常是一个应该寻找启动错误的标志,这表明真正的问题。

on visit

[Sat Oct 15 03:38:08.900966 2016] [:error] [pid 28272] [remote 95.166.81.114:39651] mod_wsgi (pid=28272): Target WSGI script '/django/GP/GP/wsgi.py' cannot be loaded as Python module.
[Sat Oct 15 03:38:08.901409 2016] [:error] [pid 28272] [remote 95.166.81.114:39651] mod_wsgi (pid=28272): Exception occurred processing WSGI script '/django/GP/GP/wsgi.py'.
[Sat Oct 15 03:38:08.901662 2016] [:error] [pid 28272] [remote 95.166.81.114:39651] Traceback (most recent call last):
[Sat Oct 15 03:38:08.902184 2016] [:error] [pid 28272] [remote 95.166.81.114:39651]   File "/django/GP/GP/wsgi.py", line 16, in <module>
[Sat Oct 15 03:38:08.902217 2016] [:error] [pid 28272] [remote 95.166.81.114:39651]     application = get_wsgi_application()
[Sat Oct 15 03:38:08.902501 2016] [:error] [pid 28272] [remote 95.166.81.114:39651]   File "/django/env/lib/python3.5/site-packages/django/core/wsgi.py", line 13, in get_wsgi_application
[Sat Oct 15 03:38:08.902529 2016] [:error] [pid 28272] [remote 95.166.81.114:39651]     django.setup(set_prefix=False)
[Sat Oct 15 03:38:08.902726 2016] [:error] [pid 28272] [remote 95.166.81.114:39651]   File "/django/env/lib/python3.5/site-packages/django/__init__.py", line 27, in setup
[Sat Oct 15 03:38:08.902755 2016] [:error] [pid 28272] [remote 95.166.81.114:39651]     apps.populate(settings.INSTALLED_APPS)
[Sat Oct 15 03:38:08.902924 2016] [:error] [pid 28272] [remote 95.166.81.114:39651]   File "/django/env/lib/python3.5/site-packages/django/apps/registry.py", line 78, in populate
[Sat Oct 15 03:38:08.902953 2016] [:error] [pid 28272] [remote 95.166.81.114:39651]     raise RuntimeError("populate() isn't reentrant")
[Sat Oct 15 03:38:08.903111 2016] [:error] [pid 28272] [remote 95.166.81.114:39651] RuntimeError: populate() isn't reentrant

start up

[Sat Oct 15 03:38:08.900966 2016] [:error] [pid 28272] [remote 95.166.81.114:39651] mod_wsgi (pid=28272): Target WSGI script '/django/GP/GP/wsgi.py' cannot be loaded as Python module.
[Sat Oct 15 03:38:08.901409 2016] [:error] [pid 28272] [remote 95.166.81.114:39651] mod_wsgi (pid=28272): Exception occurred processing WSGI script '/django/GP/GP/wsgi.py'.
[Sat Oct 15 03:38:08.901662 2016] [:error] [pid 28272] [remote 95.166.81.114:39651] Traceback (most recent call last):
[Sat Oct 15 03:38:08.902184 2016] [:error] [pid 28272] [remote 95.166.81.114:39651]   File "/django/GP/GP/wsgi.py", line 16, in <module>
[Sat Oct 15 03:38:08.902217 2016] [:error] [pid 28272] [remote 95.166.81.114:39651]     application = get_wsgi_application()
[Sat Oct 15 03:38:08.902501 2016] [:error] [pid 28272] [remote 95.166.81.114:39651]   File "/django/env/lib/python3.5/site-packages/django/core/wsgi.py", line 13, in get_wsgi_application
[Sat Oct 15 03:38:08.902529 2016] [:error] [pid 28272] [remote 95.166.81.114:39651]     django.setup(set_prefix=False)
[Sat Oct 15 03:38:08.902726 2016] [:error] [pid 28272] [remote 95.166.81.114:39651]   File "/django/env/lib/python3.5/site-packages/django/__init__.py", line 27, in setup
[Sat Oct 15 03:38:08.902755 2016] [:error] [pid 28272] [remote 95.166.81.114:39651]     apps.populate(settings.INSTALLED_APPS)
[Sat Oct 15 03:38:08.902924 2016] [:error] [pid 28272] [remote 95.166.81.114:39651]   File "/django/env/lib/python3.5/site-packages/django/apps/registry.py", line 78, in populate
[Sat Oct 15 03:38:08.902953 2016] [:error] [pid 28272] [remote 95.166.81.114:39651]     raise RuntimeError("populate() isn't reentrant")
[Sat Oct 15 03:38:08.903111 2016] [:error] [pid 28272] [remote 95.166.81.114:39651] RuntimeError: populate() isn't reentrant
[Sat Oct 15 03:38:43.291502 2016] [:error] [pid 28272] Exception ignored in: <module 'threading' from '/usr/lib/python3.4/threading.py'>
[Sat Oct 15 03:38:43.291579 2016] [:error] [pid 28272] Traceback (most recent call last):
[Sat Oct 15 03:38:43.291604 2016] [:error] [pid 28272]   File "/usr/lib/python3.4/threading.py", line 1288, in _shutdown
[Sat Oct 15 03:38:43.292356 2016] [:error] [pid 28272]     assert tlock is not None
[Sat Oct 15 03:38:43.292377 2016] [:error] [pid 28272] AssertionError: 
[Fri Oct 14 23:38:43.412942 2016] [:error] [pid 28299] Exception ignored in: <module 'threading' from '/usr/lib/python3.4/threading.py'>
[Fri Oct 14 23:38:43.413044 2016] [:error] [pid 28299] Traceback (most recent call last):
[Fri Oct 14 23:38:43.413076 2016] [:error] [pid 28299]   File "/usr/lib/python3.4/threading.py", line 1288, in _shutdown
[Fri Oct 14 23:38:43.425037 2016] [:error] [pid 28275] Exception ignored in: <module 'threading' from '/usr/lib/python3.4/threading.py'>
[Fri Oct 14 23:38:43.425125 2016] [:error] [pid 28275] Traceback (most recent call last):
[Fri Oct 14 23:38:43.425157 2016] [:error] [pid 28275]   File "/usr/lib/python3.4/threading.py", line 1288, in _shutdown
[Fri Oct 14 23:38:43.427625 2016] [:error] [pid 28274] Exception ignored in: <module 'threading' from '/usr/lib/python3.4/threading.py'>
[Fri Oct 14 23:38:43.427694 2016] [:error] [pid 28274] Traceback (most recent call last):
[Fri Oct 14 23:38:43.427722 2016] [:error] [pid 28274]   File "/usr/lib/python3.4/threading.py", line 1288, in _shutdown
[Fri Oct 14 23:38:43.432020 2016] [:error] [pid 28273] Exception ignored in: <module 'threading' from '/usr/lib/python3.4/threading.py'>
[Fri Oct 14 23:38:43.432078 2016] [:error] [pid 28273] Traceback (most recent call last):
[Fri Oct 14 23:38:43.432105 2016] [:error] [pid 28273]   File "/usr/lib/python3.4/threading.py", line 1288, in _shutdown
[Fri Oct 14 23:38:43.438577 2016] [:error] [pid 28299]     assert tlock is not None
[Fri Oct 14 23:38:43.438654 2016] [:error] [pid 28299] AssertionError: 
[Fri Oct 14 23:38:43.442174 2016] [:error] [pid 28274]     assert tlock is not None
[Fri Oct 14 23:38:43.442226 2016] [:error] [pid 28274] AssertionError: 
[Fri Oct 14 23:38:43.447227 2016] [:error] [pid 28276] Exception ignored in: <module 'threading' from '/usr/lib/python3.4/threading.py'>
[Fri Oct 14 23:38:43.447294 2016] [:error] [pid 28276] Traceback (most recent call last):
[Fri Oct 14 23:38:43.447326 2016] [:error] [pid 28276]   File "/usr/lib/python3.4/threading.py", line 1288, in _shutdown
[Fri Oct 14 23:38:43.448813 2016] [:error] [pid 28277] Exception ignored in: <module 'threading' from '/usr/lib/python3.4/threading.py'>
[Fri Oct 14 23:38:43.448876 2016] [:error] [pid 28277] Traceback (most recent call last):
[Fri Oct 14 23:38:43.448903 2016] [:error] [pid 28277]   File "/usr/lib/python3.4/threading.py", line 1288, in _shutdown
[Fri Oct 14 23:38:43.450188 2016] [:error] [pid 28273]     assert tlock is not None
[Fri Oct 14 23:38:43.450231 2016] [:error] [pid 28273] AssertionError: 
[Fri Oct 14 23:38:43.456680 2016] [:error] [pid 28275]     assert tlock is not None
[Fri Oct 14 23:38:43.456737 2016] [:error] [pid 28275] AssertionError: 
[Fri Oct 14 23:38:43.461761 2016] [:error] [pid 28277]     assert tlock is not None
[Fri Oct 14 23:38:43.461826 2016] [:error] [pid 28277] AssertionError: 
[Fri Oct 14 23:38:43.466165 2016] [:error] [pid 28276]     assert tlock is not None
[Fri Oct 14 23:38:43.466219 2016] [:error] [pid 28276] AssertionError: 
[Fri Oct 14 23:38:43.658971 2016] [mpm_prefork:notice] [pid 28268] AH00169: caught SIGTERM, shutting down
[Sat Oct 15 03:38:43.691909 2016] [:error] [pid 28272] Exception ignored in: <module 'threading' from '/usr/lib/python3.4/threading.py'>
[Sat Oct 15 03:38:43.691968 2016] [:error] [pid 28272] Traceback (most recent call last):
[Sat Oct 15 03:38:43.691996 2016] [:error] [pid 28272]   File "/usr/lib/python3.4/threading.py", line 1288, in _shutdown
[Sat Oct 15 03:38:43.693126 2016] [:error] [pid 28272]     assert tlock is not None
[Sat Oct 15 03:38:43.693159 2016] [:error] [pid 28272] AssertionError: 
[Fri Oct 14 23:38:44.490316 2016] [:warn] [pid 28349] mod_wsgi: Compiled for Python/3.4.0.
[Fri Oct 14 23:38:44.490407 2016] [:warn] [pid 28349] mod_wsgi: Runtime using Python/3.4.3.
[Fri Oct 14 23:38:44.505672 2016] [mpm_prefork:notice] [pid 28349] AH00163: Apache/2.4.7 (Ubuntu) PHP/5.5.9-1ubuntu4.19 mod_wsgi/3.4 Python/3.4.3 configured -- resuming normal operations
[Fri Oct 14 23:38:44.505764 2016] [core:notice] [pid 28349] AH00094: Command line: '/usr/sbin/apache2'

1
投票

我知道这问题已经有一段时间了,但我刚刚遇到这个问题,因为我在这里没有讨论过这个问题。由于在CentOS 7上的SELinux,我得到了RuntimeError: populate() isn't reentrant错误。我让Django服务于主目录,我只需要启用允许读取主目录的SELinux布尔值,因为populate()错误是由于权限问题。我的解决方案是setsebool -P httpd_read_user_content 1。我希望这可以帮助有这个问题的人。


1
投票

众多答案清楚地表明了这一点;这是一个通用错误,可能有多个根本原因,通常与加载Apache / WSGI有关。

这个页面上的所有这些答案应该作为一种清单,并且在这种情况下我想添加我的错误实例的根本原因:未能在settings.py文件中添加'import os'。

具体来说,我们团队中的开发人员打算删除不需要的软件包,而是从生产settings.py文件的顶部删除“import os”。 apache重新启动后,我们的应用程序将不会重新启动,我们收到了可怕的'RuntimeError:populate()不可重入'错误。

一个快速的'python manage.py check'没有透露问题,但是'python settings.py'确实存在; os包没有加载。

如果您有此错误,请将搜索重点放在检查settings.py文件以及WSGI文件上。


1
投票

如果在代码中使用空格和制表符不一致,也会生成此错误。


0
投票

我遇到了这个问题,在找回我的提交之前找不到任何答案。显然我添加了一个意外导入,因为自动完成,搞砸了设置。

# found in models.py from msilib.schema import SelfReg

在apache错误日志中:RuntimeError(“populate()不可重入”)

它在我的Windows开发环境中工作正常但在ubuntu / apache服务器上失败了。


0
投票

更改此设置的顺序后,我遇到了同样的错误:

MIDDLEWARE_CLASSES = (
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'django.middleware.security.SecurityMiddleware',
)

把它放回到此前的订单并重新启动apache修复了问题。


0
投票

在我的情况下,我为custom renderer class有一个Django Rest Framework,出于某种目的我必须覆盖渲染器类的方法“get_context”(完全披露:使django toolbar给出正确的SQL查询计数)

我删除了那个课程并重新部署。有效。


0
投票

在我的情况下发生错误是因为缺少必需的pip-package。

所以我做了一个pip install -r requirements.txt,重新启动了apache,事情又恢复了。


0
投票

删除virtualenv目录,重新创建virtualenv,然后重新安装所有要求为我修复它。


29
投票

我知道这是一个陈旧的答案,但我会为我的解决方案做出贡献:

作为一种诊断问题根源的方法,运行manage.py checkand看看你是否在那里找到任何东西

在我的情况下,过时的要求是问题,并且django未能导入子模块

确保您的要求是最新的


0
投票

RuntimeError: populate() isn't reentrant

可以是任何东西,这就是为什么这个问题有很多不同的答案。

诀窍是在RuntimeError之前查看错误消息。在您的情况下,第15行/extra/www/htmlquotes/quotes_django/quotespage/admin.py文件中似乎存在语法错误,请参阅:

Sun Nov 23 13:52:46 2014] [error] [client 128.84.33.19] File "/extra/www/htmlquotes/quotes_django/quotespage/admin.py", line 25
[Sun Nov 23 13:52:46 2014] [error] [client 128.84.33.19] pprove_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

0
投票

将我的理由添加到列表中。对我来说,这是因为我有一个django服务,其名称与进程目录相同。重命名进程/目录修复了问题。


0
投票

我有一个递归的django.setup(),例如我试图在django.setup()中写一个app/models.py,在堆栈跟踪django试图指出这附近:

... "site-packages/django/apps/config.py", line 211, in import_models
    self.models_module = import_module(models_module_name)
...
... ./myproject/myapp/models.py ...

所以是的,在设置django的时候一定不要尝试设置django ...


0
投票

为我重新启动Apache服务器解决了这个问题。您可以使用命令$ sudo service apache2 restart来实现


-1
投票

在我的情况下,我有一个循环导入,导致错误打破populate方法。


-1
投票

我解决了将__init__.py添加到我的apps文件夹的问题。

touch /mainprojectfolder/projectfolderwhichcontainswsgi.py/apps/__init__.py

然后它工作了!


-1
投票

投入2欧分:

我在Docker中重新创建了一个工作设置。新的Docker设置失败了

populate isn't reentrant

这似乎是一般错误。就我而言,我忽略了这一点

pip install Django

安装最新版本(2.0),而不是所需的版本1.11。将此更改为

pip install Django==1.11

解决了我的问题。


-1
投票

我认为当settings.py出现问题时,这是一般性错误。有时,我可以通过逐个删除已安装的应用程序来反复查找问题。在某些情况下,它与已安装的应用程序无关。但根据我的经验,在所有情况下它都是settings.py文件中的问题。


-1
投票

检查你是否在settings.py的安装应用程序部分中提到了两次api名称。

应用定义

INSTALLED_APPS = [
    ...
    'rest_framework',
    'myapp_api',
    'myapp_api.apps.myappWebserviceApiConfig',    
]

应用定义

INSTALLED_APPS = [
    ...
    'rest_framework',
    'myapp_api.apps.myappWebserviceApiConfig',
]

删除重复的条目解决了我的问题


-1
投票

我最近在我的django项目[Django1.11]上遇到了同样的错误。

问题是我的应用程序不再存在于非标准的django位置,通常应用程序位于根项目目录中

我最近将我的应用程序移动到应用程序文件夹以进行日志记录,但我忘了更新我的模板。

我的结构[./awesome_potatoes/apps/first_app/]

因此,当我开始一个新的应用程序时,由于过时的模板,django不会在apps.py文件或任何python文件中添加dir名称

apps.朋友

name = 'first_app'

修复[更新我的模板后]

name = 'apps.first_app'


8
投票

如果您在使用Google App Engine时遇到此错误,请检查日志中是否存在可能导致此问题的其他错误。我得到了:

ImproperlyConfigured: Error loading either pysqlite2 or sqlite3 modules (tried in that order): No module named _sqlite3

您不能将SQLite与Google App Engine一起使用,因此评论DATABASESsettings.py部分也会停止该错误以及RuntimeError("populate() isn't reentrant")错误。


-1
投票

我不愿意将此作为答案添加,因为它实际上只是对相关案例的描述。然而,作为评论,它似乎不易读。

我在创建一个可以在没有服务器运行的情况下访问Django数据库的函数时遇到了这个错误。大多数情况下,这用于插入测试数据条目。

我的项目在project/apps/app_one/functions.py文件中有以下内容:

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "Project.settings")
import django
django.setup()

这允许在没有服务器运行的情况下通过Python脚本访问Django数据库。有关此方法的更多信息,请参见此处:https://stackoverflow.com/a/26875729/4573162

我还在此文件中保留了基本的应用程序功能,这些功能不需要数据库访问,并且在服务器运行时使用。例如,在我的app_one.models.py中,我可能会使用从functions.arg_format文件导入的app_name/functions.py函数:

def save(self, *args, **kwargs):
    self.some_arg = functions.arg_format(self.some_arg)
    super().save(*args, **kwargs)

这相当于我的应用程序在运行时试图再次运行Django setup()

我不知道这是多么相关,但它引发了相同的RuntimeError: populate() isn't reentrant错误,直到我为所有数据库访问函数创建了一个单独的文件。在回避了额外的setup()导入后,迁移能够按预期完成。


3
投票

您可以通过触摸加载过程中早期的文件(wsgi.py除外)重新启动Apache,也可以修复它。例如,您的设置文件:

$ touch settings.py

我也没有正确解决这个问题,但在我的问题中有更多信息:Code change monitoring malfunctioning with Django 1.7 on mod-wsgi


3
投票

这不是回应,而是反思。

当你升级到django 1.7并且你有500错误并重新加载你的页面时,Apache说“populate()不是可重入的”。我认为这是在你加载你的页面时,Apache加载你的应用程序所需的所有模块,当错误处理时它不会卸载模块。因此,当您重新加载页面时,apache会再次加载这些模块,但它已经加载了。所以,apache说“populate()不是可重入的”。

我有两个操作来纠正这个问题:重启apache,或者更正处理第一个5OO错误的错误。

我希望它会对你有所帮助。


3
投票

这是由某个地方的Django设置中的错误引起的。不幸的是,Django隐藏了这个通用且无用的错误消息背后的bug。

要揭示真正的问题,打开django/apps/registry.py和第80行,替换:

raise RuntimeError("populate() isn't reentrant")

有:

self.app_configs = {}

这将允许Django继续加载,并揭示实际错误。

我遇到了几个不同原因的错误。曾经是因为我在我的应用程序的一个admin.py中导入错误。


2
投票

对于同一个Apache mod-wsgi错误,这看起来像一个很好的有效响应集合,每个人发布一个适合他/她的那个,所以这是我的:

部署后不要忘记更新项目要求:)


2
投票

Apache将wsgi文件存储在其缓存中。 Disable Apache caching of python files

因此,首先删除wsgi文件并重新启动acpache,然后再次添加wsgi文件并重新启动apache。


2
投票

我遇到了同样的问题,我的错误来源只是我正在使用的文件中的语法错误。修正错字后,populate() is not reentrant错误消失了。

如果从wsgi脚本运行django,则可以通过从命令行运行wsgi脚本来识别拼写错误。例如:

cd /usr/local/www/wsgi-scripts/
python djangolauncher.wsgi
© www.soinside.com 2019 - 2024. All rights reserved.