Python Django populate() 不可重入

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30954398/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 09:13:47  来源:igfitidea点击:

Django populate() isn't reentrant

pythondjangoapache

提问by ip.

I keep getting this when I try to load my Django application on production . I tried all the stackoverflow answers but nothing has fixed it. Any other ideas. (I'm using Django 1.5.2 and Apache)

当我尝试在生产中加载我的 Django 应用程序时,我一直收到这个。我尝试了所有 stackoverflow 的答案,但没有任何解决方法。任何其他想法。(我使用的是 Django 1.5.2 和 Apache)

 Traceback (most recent call last):
         File "/var/www/thehomeboard/wwwhome/wsgi.py", line 37, in <module>
           application = get_wsgi_application()
         File "/usr/local/lib/python2.7/dist-packages/django/core/wsgi.py", line 14, in get_wsgi_application
           django.setup()
         File "/usr/local/lib/python2.7/dist-packages/django/__init__.py", line 18, in setup
           apps.populate(settings.INSTALLED_APPS)
         File "/usr/local/lib/python2.7/dist-packages/django/apps/registry.py", line 78, in populate
           raise RuntimeError("populate() isn't reentrant")
       RuntimeError: populate() isn't reentrant

采纳答案by ip.

In the end the problem that I had was that I tried to run a second Django app and did not have the following defined in my apache config:

最后,我遇到的问题是我尝试运行第二个 Django 应用程序,但我的 apache 配置中没有定义以下内容:

WSGIDaemonProcess ...
WSGIProcessGroup ...

Just learned that you can run a single django app without defining them but when its two it produces a conflict.

刚刚了解到您可以在不定义它们的情况下运行单个 django 应用程序,但是当它两个时会产生冲突。

回答by Dirk Eschler

This RuntimeError first occured for me after upgrading to Django 1.7 (and still is present with Django 1.8). It is usually caused by an Django application which raises an error, but that error is swallowed somehow.

在升级到 Django 1.7(并且仍然存在于 Django 1.8)之后,这个 RuntimeError 首先发生在我身上。它通常是由引发错误的 Django 应用程序引起的,但该错误以某种方式被吞下。

Here's a workaround which works for me. Add it to your wsgi.py and the realerror should be logged:

这是一个对我有用的解决方法。将它添加到您的 wsgi.py 并记录真正的错误:

import os
import time
import traceback
import signal
import sys
from django.core.wsgi import get_wsgi_application

try:
    application = get_wsgi_application()
    print 'WSGI without exception'
except Exception:
    print 'handling WSGI exception'
    # Error loading applications
    if 'mod_wsgi' in sys.modules:
        traceback.print_exc()
        os.kill(os.getpid(), signal.SIGINT)
        time.sleep(2.5)

See this threadon modwsgi for more details.

有关更多详细信息,请参阅modwsgi 上的此线程

回答by Harun ERGUL

There will be many reason to causes to populate() isn't reentranterror. If you look at the registry.pyin your in django application probably inside this directory
/python2.7/site-packages/django/apps

导致populate() isn't reentrant错误的原因有很多。如果registry.py您在 django 应用程序中查看可能在此目录中
/python2.7/site-packages/django/apps

        # app_config should be pristine, otherwise the code below won't
        # guarantee that the order matches the order in INSTALLED_APPS.
        if self.app_configs:
            raise RuntimeError("populate() isn't reentrant")

As you see in the comment it says app_config should be pristine. Which means if one of configuration is not correct or required library missing it will rise this populate error. I got this error because I have missed sqlite installation. Even as you see there is no mentioning possible causes in the exception. I installed sqlite by this command on debian

正如您在评论中看到的,它说 app_config 应该是原始的。这意味着如果其中一个配置不正确或缺少所需的库,则会出现此填充错误。我收到此错误是因为我错过了 sqlite 安装。即使如您所见,异常中也没有提及可能的原因。我在 debian 上通过这个命令安装了 sqlite

pip install pysqlite

It solved my problem. My exception because of missing pysqlite.Your maybe having missing of another required packages or errors in your settings.py

它解决了我的问题。我的例外是因为缺少 pysqlite。您可能缺少另一个必需的软件包或错误settings.py

回答by MontyThreeCard

Full disclosure - "populate() isn't reentrant" errors can have multiple causes, and checking any recent config or program changes is a very good idea.

全面披露 - “populate() is not reentrant”错误可能有多种原因,检查任何最近的配置或程序更改是一个非常好的主意。

However, this error can also occur when Apache is updated, and a module is no longer valid/is corrupted/needs refreshing. This occurred to us on Webfaction after an Apache update (but may happen on any host).

但是,当 Apache 更新并且模块不再有效/已损坏/需要刷新时,也会发生此错误。在 Apache 更新后,我们在 Webfaction 上发生了这种情况(但可能发生在任何主机上)。

Using the Apache restart script will NOT help this, because the modules remain loaded on the restart. Depending on your system, and whether the mods are cached even when Apache is shut down, this may help.

使用 Apache 重启脚本对此没有帮助,因为模块在重启时仍保持加载状态。根据您的系统,以及即使 Apache 关闭时 mod 是否也被缓存,这可能会有所帮助。

Fully stop Apache. On Webfaction, that is:

完全停止Apache。在 Webfaction 上,即:

~/webapps/<YOUR WEB APP>/apache2/bin/stop

Wait a few seconds, and then...

等待几秒钟,然后...

~/webapps/<YOUR WEB APP>/apache2/bin/start

That should correct the issue. If your system caches the mods, you may have to flush the cache before starting.

那应该纠正这个问题。如果您的系统缓存了 mod,您可能需要在开始之前刷新缓存。

Hope this helps!

希望这可以帮助!

Here is the link they gave me (I know the error is different, but we had this happen for the same reason with the populate error as well):

这是他们给我的链接(我知道错误是不同的,但我们也出于同样的原因与填充错误发生了这种情况):

https://statusblog.webfaction.com/2018/05/16/regarding-glibc_private-errors-in-your-python-application/

https://statusblog.webfaction.com/2018/05/16/regarding-glibc_private-errors-in-your-python-application/

回答by python1981

For those using AWS Lambda(and optionally using zappa) this can happen when the size of code & dependencies zipped into a deployment package exceeds 250MB after decompression.

对于那些使用AWS Lambda(也可以选择使用 zappa)的用户,当解压后压缩到部署包中的代码和依赖项的大小超过 250MB 时,就会发生这种情况。

Typically the zip may only be 50 MB but may decompress to over 250MB so you may need to manually unzip the deployment package to check it isn't too large when uncompressed.

通常 zip 可能只有 50 MB,但可能会解压到超过 250 MB,因此您可能需要手动解压缩部署包以检查解压缩时它是不是太大。

https://docs.aws.amazon.com/lambda/latest/dg/limits.html

https://docs.aws.amazon.com/lambda/latest/dg/limits.html

回答by J. Hesters

For me this error was caused, because I hadn't correctly split my INSTALLED_APPSfor local and production. Meaning in local I was using django-cors-headersand in production I was not. But I accidentally had left django-cors-headerseven though I removed it from my production requirements.txt. After delete cors-headersfrom the installed apps in production the error went away.

对我来说,这个错误是造成的,因为我没有正确地将我INSTALLED_APPS的本地和生产分开。意思是我在本地使用,django-cors-headers而在生产中我没有。但是我不小心离开了,django-cors-headers即使我从我的作品中删除了它requirements.txtcors-headers从生产中已安装的应用程序中删除后,错误消失了。