168

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

所以我修复了语法错误,检查了我没有更多的 with 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

populate从 的方法抛出registry.py

谷歌搜索此错误消息返回的信息非常少,没有来自 Django 文档。显然,如果您在 中两次命名一个应用程序,有时可能会发生这种情况settings.py,但我没有这样做。更重要的是,自从网站正常运行以来,我就没有改变settings.py过——我唯一改变的是admin.py.

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

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

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

注意:我使用的是 Django 1.7、Apache 2.2 和 Python 2.7。

4

38 回答 38

212

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

为了揭示真正的问题,打开django/apps/registry.py并在第 80 行附近,替换:

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

和:

self.app_configs = {}

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

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

于 2019-04-30T21:53:12.937 回答
69

我的服务器管理员重新启动了 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 权限的情况下这样做。

于 2014-11-24T15:59:17.090 回答
53

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

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

在我的情况下,问题是过时的要求,django 无法导入子模块

确保您的要求是最新的

于 2017-04-14T15:56:17.027 回答
17

这不是回应,而是反思。

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

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

尝试使用以下命令重新启动 apache:

sudo service httpd restart

我希望它会帮助你。

于 2014-11-24T10:24:50.630 回答
10

如果您在使用 Google App Engine 时遇到此错误,请检查您的日志以查找可能导致此错误的其他错误。我得到:

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

您不能将 SQLite 与 Google App Engine 一起使用,因此请注释掉停止该错误和错误的DATABASES部分。settings.pyRuntimeError("populate() isn't reentrant")

于 2015-05-14T17:00:02.547 回答
4

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

$ touch settings.py

我也没有正确解决这个问题,但我的问题中有更多信息:代码更改监控在 mod-wsgi 上使用 Django 1.7 出现故障

于 2015-01-06T18:10:50.307 回答
3

Apache 将 wsgi 文件存储在其缓存中。 禁用 python 文件的 Apache 缓存

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

于 2016-05-26T07:17:01.077 回答
3

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

于 2018-06-30T18:44:17.210 回答
2

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

如果您从 wsgi 脚本运行 django,则只需从命令行运行 wsgi 脚本即可识别错字。例如:

cd /usr/local/www/wsgi-scripts/
python djangolauncher.wsgi
于 2015-03-31T16:12:48.323 回答
2

如果您在开发环境中测试了语法并且一切正常,那么问题就在这里

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,它与我的答案一样工作!

于 2020-12-01T21:30:40.263 回答
2

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

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

我所做的就是做一遍chown user:group /to/path -Rchmod 770 /to/path -R一遍,它奏效了。

于 2015-11-11T06:17:51.747 回答
2

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

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

于 2016-01-27T14:24:36.590 回答
1

关于 AWS Elastic Beanstalk 的注意事项:settings.py由 Django-admin 编写的默认值包括对本地 sqlite 数据库的引用作为数据源。这可能适用于您的本地操作系统,但不适用于 AWS EB,并且会出现populate() isn't reentrant运行时错误。DATABASES={<...>}要对此进行测试,只需将 中的语句注释掉settings.py,部署并重新打开应用程序即可。

于 2019-09-21T11:00:35.047 回答
1

众多的答案说明了一切;这是一个一般性错误,可能有多个根本原因,通常与加载 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 文件上。

于 2018-04-08T12:50:33.703 回答
1

我有一个 recursive django.setup(),例如我试图django.setup()在一个 an 内写一个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 ......

于 2019-05-13T20:08:25.253 回答
1

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

于 2017-03-08T13:39:42.663 回答
1

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
于 2019-02-01T20:21:09.940 回答
1

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

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

然后我改为搜索启动错误的解决方案,这个问题的解决方案对我有用。简而言之,它涉及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'
于 2016-10-15T04:12:49.660 回答
0

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

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

在 apache 错误日志中: RuntimeError("populate() is not reentrant")

它在我的 windows 开发环境中运行良好,但在 ubuntu/apache 服务器上失败了。

于 2015-06-12T01:25:26.630 回答
0

我犹豫将其添加为答案,因为它实际上只是对相关案例的描述。但是,它似乎不像评论那样清晰。

在创建一个无需服务器运行即可访问 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_formatapp_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()导入后,迁移能够按预期完成。

于 2018-10-17T17:00:21.810 回答
0

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

于 2018-02-28T18:38:36.783 回答
0

对我来说,问题在于 SQLite 的版本。我切换到 MySQL,一切正常。PS:我正在使用 Namecheap 的共享主机。因此,要安装 mysqlclient,我必须联系支持人员。

于 2021-11-06T18:04:42.177 回答
0

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

于 2019-06-14T10:10:35.340 回答
0

就我而言,我mysqlclient没有安装。不幸的是,Django 隐藏了这个通用且无用的错误消息背后的错误。

为了揭示真正的问题,打开 django/apps/registry.py 并围绕第80行,替换:

$ raise RuntimeError("populate() isn't reentrant") 和: $self.app_configs = {}

然后检查错误,Log找到实际的错误。修复该问题并再次重新启动 apache 服务器。

于 2021-03-31T09:55:41.110 回答
0

对我来说,错误是 requirements.txt 文件中缺少一个mysqlclient包。

首先我安装了这个mysqlclient包:

pip install mysqlclient

然后我更新了 requirements.txt 文件:

pip freeze > requirements.txt

这解决了我的问题。

于 2020-02-26T08:40:14.000 回答
0

我遇到了同样的问题,对我有用的是注释掉 / settings.py 中的默认数据库设置。我还读到 django 的更高版本与 ebs 不兼容

于 2019-10-08T03:47:27.397 回答
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 解决了这个问题。

于 2015-11-01T18:29:20.200 回答
0

就我而言,我有一个循环导入,这会导致一个错误,破坏填充方法。

于 2017-08-03T22:11:20.933 回答
0

就我而言,发生错误是因为缺少必需的 pip 包。

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

于 2017-07-26T09:39:53.713 回答
0

就我而言,我有一个custom renderer classfor Django Rest Framework,出于某种目的,我不得不覆盖渲染器类的方法“get_context”(完全披露:django toolbar给出正确的 SQL 查询计数)

我删除了该类并重新部署。有效。

于 2016-08-12T12:16:39.970 回答
0

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

于 2019-05-12T03:56:18.713 回答
0

在 apps.py 中,我设置了与我的应用名称不同的名称。

于 2021-06-09T10:42:46.700 回答
-1

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

于 2018-03-01T09:09:01.263 回答
-1

投入我的 2 欧分:

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

populate isn't reentrant

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

pip install Django

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

pip install Django==1.11

解决了我的问题。

于 2018-01-01T13:43:14.290 回答
-1

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

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

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

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

因此,当我启动一个新应用程序时,由于模板过时,django 不会在 apps.py 文件或任何 python 文件中预先添加目录名称

应用程序.py

name = 'first_app'

修复 [更新我的模板后]

name = 'apps.first_app'

于 2018-10-03T15:12:56.837 回答
-1

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

应用程序定义

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

应用程序定义

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

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

于 2018-07-03T05:45:49.197 回答
-2

我解决了添加__init__.py到我的应用程序文件夹的问题。

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

然后它起作用了!

于 2017-10-03T22:01:14.263 回答
-5

这是您的 PC/主机/VPS内存不足的原因,请释放一些内存,一切都会好起来的。

于 2015-09-21T16:16:47.980 回答