我一直在使用 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
第一系列错误显示 WSGI 由于我的 admin.py
中的语法错误而失败。但是,第二系列错误似乎显示了 Django 内部的错误:
RuntimeError: populate() isn't reentrant
从 registry.py
的 populate
方法抛出。
谷歌搜索此错误消息返回的信息非常少,没有来自 Django 文档。显然,如果您在 settings.py
中两次命名应用程序,有时会发生这种情况,但我没有这样做。更重要的是,自从网站正常运行以来,我没有更改 settings.py
—— 我唯一更改的是 admin.py
。
我尝试恢复我所做的所有更改,所以我的所有 Python 代码都恢复到网站运行时的状态——当我尝试让 WSGI 重新加载代码时,我仍然收到 populate() isn't reentrant
错误!
我还尝试在 settings.py
的 INSTALLED_APPS 部分中注释掉不同的应用程序,即使只启用了“django.contrib.staticfiles”,错误仍然会发生。奇怪的是,即使我注释掉 all 应用程序,我仍然会收到错误消息——即使没有加载任何应用程序,Django 也会抛出错误!
有谁知道这里发生了什么?或者有什么更好的方法让我调试这个错误,因为 Apache 日志中的回溯非常无用?
注意:我使用的是 Django 1.7、Apache 2.2 和 Python 2.7。
wsgi.py
会导致相同的 Apache 错误,并且不会重新创建 .pyc 文件。
这是由您的 Django 设置中的某个错误引起的。不幸的是,Django 隐藏了这个通用且无用的错误消息背后的错误。
要揭示真正的问题,请打开 django/apps/registry.py
并在第 80 行附近替换:
raise RuntimeError("populate() isn't reentrant")
和:
self.app_configs = {}
这将允许 Django 继续加载,并显示实际错误。
由于几个不同的原因,我遇到了这个错误。曾经是因为我在我的一个应用程序的 admin.py 中有一个错误的导入。
我的服务器管理员重新启动了 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 权限的情况下这样做。
startup-timeout
选项,它有助于在初始化 Django 时从暂时性错误中恢复,例如数据库不可用。如果 WSGI 应用程序在超时时间后没有正确加载,超时将导致进程自动重新启动。即使这对您自己的代码存在永久性问题也无济于事。在这种情况下,请查找第一个错误,而不是 populate()
错误,因为它会给出您的代码失败的真正原因。
我知道这是一个旧答案,但我会为我的解决方案做出贡献:
作为诊断问题根源的一种方法,请运行manage.py check
并查看您是否在其中找到任何东西
在我的情况下,问题是过时的要求,django 无法导入子模块
确保您的要求是最新的
manage.py check
我发现了问题。谢谢你。
这不是回应,而是反思。
当您升级到 django 1.7 并出现 500 错误并重新加载页面时,Apache 说“populate() 不可重入”。我认为是当您加载页面时,Apache 会加载您的应用程序所需的所有模块,并且在处理错误时它不会卸载模块。因此,当您重新加载页面时,apache 会再次加载这些模块,但它已经加载了。因此,apache 说“populate() 不可重入”。
我有两个操作来纠正这个问题:重新启动 apache,或者纠正处理第一个 5OO 错误的错误。
尝试使用以下命令重新启动 apache:
sudo service httpd restart
我希望它会帮助你。
sudo /etc/init.d/apache2 reload
sudo systemctl restart apache2
现在我还有其他问题!
如果您在使用 Google App Engine 时遇到此错误,请检查您的日志以查找可能导致此错误的其他错误。我得到:
ImproperlyConfigured: Error loading either pysqlite2 or sqlite3 modules (tried in that order): No module named _sqlite3
您不能将 SQLite 与 Google App Engine 一起使用,因此注释掉 settings.py
的 DATABASES
部分会停止该错误以及 RuntimeError("populate() isn't reentrant")
错误。
您可以通过触摸加载过程早期的文件(wsgi.py 除外)来修复它而无需重新启动 Apache。例如,您的设置文件:
$ touch settings.py
我也没有正确解决这个问题,但我的问题中有更多信息:Code change monitoring malfunctioning with Django 1.7 on mod-wsgi
Apache 将 wsgi 文件存储在其缓存中。 Disable Apache caching of python files
因此,首先删除 wsgi 文件并重新启动您的 acpache,然后再次添加 wsgi 文件并重新启动 apache。
如果代码中空格和制表符的使用不一致,也会产生此错误。
我刚遇到同样的问题,所以我开始环顾四周。
现在我已经开始工作了,所以我想我应该与你们分享!
我所做的只是重新做 chown user:group /to/path -R
和 chmod 770 /to/path -R
并且它起作用了。
这看起来像是对同一个 Apache mod-wsgi 错误的有效响应的一个很好的集合,每个人都发布了对他/她有用的响应,所以这是我的:
部署后不要忘记更新您的项目需求:)
我遇到了同样的问题,对我来说,错误的根源只是我正在使用的文件中的语法错误。修正错字后,populate() is not reentrant
错误消失了。
如果您从 wsgi 脚本运行 django,则只需从命令行运行 wsgi 脚本即可识别错字。例如:
cd /usr/local/www/wsgi-scripts/
python djangolauncher.wsgi
如果您在开发环境中测试了语法并且一切正常,那么问题就在这里
WSGIDaemonProcess celeryEnv python-path=/var/www/celeryEnv/lib/python3.6/site-packages user=apache group=apache python-home=/var/www/celeryEnv
apache只看
python-path=/var/www/celeryEnv/lib/python3.6/site-packages
所以 lib64 中的任何模块都不会在 apache 中被识别
我通过处理所有模块在 /var/www/celeryEnv/lib64
到 /var/www/celeryEnv/lib
中找到了解决方法
现在 apache 可以在我自己的服务器上运行
WSGIDaemonProcess domain.com python-path=/home/user/app/env/lib/python3.6/site-packages:/home/user/app
注意:这里已经有有益的信息,但我提出这个答案是因为我的服务器主要是 Centos-7,它与我的答案一样工作!
设置: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
错误通常表明应该寻找启动错误,这表明真正的问题。
访问中
[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: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'
populate()
问题,而且在我看来是一个完全不同的问题,所以我看不出你认为它是如何解决同一个问题的。因此,据任何人所知,您有一个不同的问题,您应该在一开始就提出一个单独的问题,而不是混淆这里的回答,因为根据其他帖子中的细节看起来像一个不同的问题..
我知道自从提出这个问题以来已经有一段时间了,但是由于我没有在这里讨论过的问题,我刚刚遇到了这个问题。由于 CentOS 7 上的 SELinux,我收到了 RuntimeError: populate() isn't reentrant
错误。我让 Django 从主目录中提供服务,我只需要启用允许读取主目录的 SELinux 布尔值,因为 populate() 错误是由于权限问题。我的解决方案是setsebool -P httpd_read_user_content 1
。我希望这可以帮助遇到这个问题的人。
chcon
将问题 .so
文件的上下文更改为 httpd_sys_script_exec_t
来修复它。
众多的答案说明了一切;这是一个一般性错误,可能有多个根本原因,通常与加载 Apache/WSGI 有关。
此页面上的所有这些答案都应该作为一种清单起作用,并且在这种情况下,我想添加我的这个错误实例的根本原因:未能将“导入操作系统”添加到您的 settings.py 文件。
具体来说,我们团队中有一个开发人员打算删除一个不需要的包,而是从生产 settings.py 文件的顶部删除了“import os”。在 apache 重启后,我们的应用程序不会重启,并且我们收到了可怕的“RuntimeError: populate() is not reentrant”错误。
快速的“python manage.py check”没有发现问题,但“python settings.py”却发现了;未加载 os 包。
如果您遇到此错误,请将搜索重点放在检查 settings.py 文件和 WSGI 文件上。
reentrant
错误。在守护程序模式下,如果您由于暂时错误而不是编码错误而遇到此问题,请确保您使用的是 startup-timeout
选项。至少这样它可以自动恢复。
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
我有一个递归 django.setup()
,例如我试图在一个 app/models.py
内写一个 django.setup()
,在堆栈跟踪中 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 ......
django.setup()
,这些任务可以工作,但我得到 Populate isn't reentrant
。
@shared_task
装饰器的部分原因是让 celery init 与 django init 配合得很好
tasks.py
文件来保存所有任务。我已经发布了一个关于此的新问题。 - stackoverflow.com/questions/66648110/…
关于 AWS Elastic Beanstalk 的注意事项:由 Django-admin 编写的默认 settings.py
包含对本地 sqlite 数据库的引用作为数据源。这可能适用于您的本地操作系统,但不适用于 AWS EB,并且会出现 populate() isn't reentrant
运行时错误。要对此进行测试,只需注释掉 settings.py
中的 DATABASES={<...>}
语句,部署并重新打开应用程序。
django.core.exceptions.ImproperlyConfigured: SQLite 3.8.3 or later is required (found 3.7.17).
,然后是 RuntimeError: populate() isn't reentrant
。来自 AWS docs:“Django 2.2 与 Elastic Beanstalk Python 3.6 平台不兼容。” (在撰写本文时)
在我回溯我的提交之前,我遇到了这个问题并且找不到任何答案。显然,由于自动完成,我添加了一个意外导入,这搞砸了设置。
# found in models.py from msilib.schema import SelfReg
在 apache 错误日志中: RuntimeError("populate() is not reentrant")
它在我的 windows 开发环境中运行良好,但在 ubuntu/apache 服务器上失败了。
更改此设置的顺序后,我遇到了同样的错误:
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 解决了这个问题。
在我的例子中,我有一个 custom renderer class
用于 Django Rest Framework
,出于某种目的,我不得不重写渲染器类的方法“get_context”(完全披露:让 django toolbar
给出正确的 SQL 查询计数)
我删除了该类并重新部署。有效。
就我而言,发生错误是因为缺少必需的 pip 包。
所以我做了一个pip install -r requirements.txt
,重新启动了 apache,一切又恢复了。
就我而言,我有一个循环导入,这会导致一个错误,破坏填充方法。
删除 virtualenv 目录,重新创建 virtualenv,然后重新安装所有为我修复的要求。
我犹豫将其添加为答案,因为它实际上只是对相关案例的描述。但是,它似乎不像评论那样清晰。
在创建一个无需服务器运行即可访问 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
中,我可能对从 app_name/functions.py
文件导入的 functions.arg_format
函数有以下用法:
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()
导入后,迁移能够按预期完成。
将我的理由添加到列表中。对我来说,这是因为我有一个 django 服务,其名称与进程目录相同。重命名进程/目录解决了这个问题。
为我重新启动 Apache 服务器解决了这个问题。您可以使用命令 $ sudo service apache2 restart 来做到这一点
我遇到了同样的问题,对我有用的是注释掉 / settings.py 中的默认数据库设置。我还读到 django 的更高版本与 ebs 不兼容
对我来说,错误是 requirements.txt 文件中缺少 mysqlclient
包。
首先,我安装了 mysqlclient
软件包:
pip install mysqlclient
然后我更新了 requirements.txt 文件:
pip freeze > requirements.txt
这解决了我的问题。
就我而言,我没有安装 mysqlclient
。不幸的是,Django 隐藏了这个通用且无用的错误消息背后的错误。
要揭示真正的问题,请打开 django/apps/registry.py
并在 80 行周围,替换:
$ raise RuntimeError("populate() isn't reentrant")
与:$self.app_configs = {}
然后检查错误,Log找到实际的错误。修复该问题并再次重新启动 apache 服务器。
不定期副业成功案例分享
django.core.exceptions.ImproperlyConfigured: psycopg2_version 2.5.4 or newer is required; you have 2.5 (dt dec pq3 ext)
pip install --upgrade psycopg2
并修复了它。