【问题标题】:django web-config azure gives error "RuntimeError: populate() isn't reentrant"django web-config azure 给出错误“RuntimeError: populate() is not reentrant”
【发布时间】:2018-12-26 21:28:02
【问题描述】:

我通过 GitHub 将本地开发的 Django Web 应用程序部署到 azure 中,当我尝试运行 URL 时,web.config 文件中出现以下错误

 Error occurred while reading WSGI handler:

Traceback (most recent call last):
  File "D:\home\python364x64\wfastcgi.py", line 791, in main
    env, handler = read_wsgi_handler(response.physical_path)
  File "D:\home\python364x64\wfastcgi.py", line 633, in read_wsgi_handler
    handler = get_wsgi_handler(os.getenv("WSGI_HANDLER"))
  File "D:\home\python364x64\wfastcgi.py", line 605, in get_wsgi_handler
    handler = handler()
  File ".\ptvs_virtualenv_proxy.py", line 107, in get_venv_handler
    handler = get_wsgi_handler(os.getenv('WSGI_ALT_VIRTUALENV_HANDLER'))
  File ".\ptvs_virtualenv_proxy.py", line 65, in get_wsgi_handler
    handler = handler()
  File "D:\home\site\wwwroot\env\lib\site-packages\django\core\wsgi.py", line 12, in get_wsgi_application
    django.setup(set_prefix=False)
  File "D:\home\site\wwwroot\env\lib\site-packages\django\__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "D:\home\site\wwwroot\env\lib\site-packages\django\apps\registry.py", line 81, in populate
    raise RuntimeError("populate() isn't reentrant")
RuntimeError: populate() isn't reentrant


StdOut: 

StdErr:

这是我的 web.config 文件:

    <?xml version="1.0" encoding="utf-8"?>
<configuration>
    <system.web>
        <compilation debug="true" targetFramework="4.0" />
      <customErrors mode="Off" />
    </system.web>
    <appSettings>
      <add key="WSGI_ALT_VIRTUALENV_HANDLER" value="django.core.wsgi.get_wsgi_application()" />
      <add key="WSGI_ALT_VIRTUALENV_ACTIVATE_THIS" value="D:\home\site\wwwroot\env\Scripts\python.exe" />
      <add key="WSGI_HANDLER" value="ptvs_virtualenv_proxy.get_venv_handler()" />
      <add key="PYTHONPATH" value="D:\home\site\wwwroot" />
      <add key="DJANGO_SETTINGS_MODULE" value="FinTech.settings" />
      <add key="WSGI_LOG" value="D:\home\LogFiles\wfastcgi.log"/>
    </appSettings>
    <system.webServer>
      <httpErrors errorMode="Detailed" />
      <handlers>
        <add name="PythonHandler" path="*" verb="*" modules="FastCgiModule" scriptProcessor="D:\home\python364x64\python.exe|D:\home\python364x64\wfastcgi.py" resourceType="Unspecified" requireAccess="Script"/>
      </handlers>
      <rewrite>
        <rules>
          <rule name="Static Files" stopProcessing="true">
            <conditions>
              <add input="true" pattern="false" />
            </conditions>
          </rule>
          <rule name="Configure Python" stopProcessing="true">
            <match url="(.*)" ignoreCase="false" />
            <conditions>
              <add input="{REQUEST_URI}" pattern="^/static/.*" ignoreCase="true" negate="true" />
            </conditions>
            <action type="Rewrite" url="handler.fcgi/{R:1}" appendQueryString="true" />
          </rule>
        </rules>
      </rewrite>
    </system.webServer>
  </configuration>

我的代码有问题还是我需要安装一些额外的要求?我在尝试在 Azure 中运行 django Web 应用程序时遇到此错误,当我在本地运行我的 Web 应用程序时它工作正常。

【问题讨论】:

  • 建议您检查下面的 GitHub 链接,并确保您的 web.config 和所有其他文件没有任何冲突数据等,github.com/MicrosoftDocs/azure-docs/blob/master/articles/…
  • 我试过了,但错误仍然没有改变。当我打开我的 azure 应用程序的控制台并运行“manage.py runserver”时,它给了我一个错误为“Traceback(最近一次调用最后一次):文件“D:\home\site\wwwroot\manage.py”,第 12 行,在 中“无法导入 Django。您确定它已安装并且“ ImportError:无法导入 Django。您确定它已安装并在您的 PYTHONPATH 环境变量中可用吗?您忘记激活虚拟环境了吗?”

标签: django azure web-config


【解决方案1】:

RuntimeError: populate() 不可重入

我将我的 django 应用部署到 azure,但没有重现您的问题。据我所知,这意味着其中一个配置不正确或缺少所需的库会引发此填充错误。

我建议您将以下代码添加到您的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)

更多解决方案,请参考以下主题:

1.Django populate() isn't reentrant

2.Django stops working with RuntimeError: populate() isn't reentrant

希望对你有帮助。

【讨论】:

  • 感谢您的回复。我尝试将上面的代码添加到我的 wsgi.py 文件中,但它仍然给了我同样的错误“RuntimeError: populate() is not reentrant”,我还提到了上面的链接,但它们都不起作用。
猜你喜欢
  • 2020-08-10
  • 1970-01-01
  • 2021-06-13
  • 2019-07-23
  • 2022-08-03
  • 1970-01-01
  • 2012-05-22
  • 2021-12-01
  • 2015-05-04
相关资源
最近更新 更多