【问题标题】:RuntimeError: populate() isn't reentrant on CentOS 7 | django 1.9 | python3RuntimeError: populate() 在 CentOS 7 上不可重入 | django 1.9 |蟒蛇3
【发布时间】:2017-03-10 09:43:27
【问题描述】:

我正在 Intranet 环境中部署一个 django 应用程序。我已经设置了一个测试服务器,一切都很好(在解决了我的头部修复错误之后)。

这一次,我设置了生产服务器,在配置完所有内容后,我得到了一个错误 500,这是 httpd/logs/error_log

追溯

[Thu Oct 27 09:44:15.480662 2016] [:error] [pid 15250] [remote 10.105.40.106:200] mod_wsgi (pid=15250): Target WSGI script '/home/rortega/smce/smce/wsgi.py' cannot be loaded as Python module.
[Thu Oct 27 09:44:15.480706 2016] [:error] [pid 15250] [remote 10.105.40.106:200] mod_wsgi (pid=15250): Exception occurred processing WSGI script '/home/rortega/smce/smce/wsgi.py'.
[Thu Oct 27 09:44:15.480736 2016] [:error] [pid 15250] [remote 10.105.40.106:200] Traceback (most recent call last):
[Thu Oct 27 09:44:15.480764 2016] [:error] [pid 15250] [remote 10.105.40.106:200]   File "/home/rortega/smce/smce/wsgi.py", line 16, in <module>
[Thu Oct 27 09:44:15.480805 2016] [:error] [pid 15250] [remote 10.105.40.106:200]     application = get_wsgi_application()
[Thu Oct 27 09:44:15.480823 2016] [:error] [pid 15250] [remote 10.105.40.106:200]   File "/home/rortega/smce_env/lib/python3.5/site-packages/django/core/wsgi.py", line 13, in get_wsgi_application
[Thu Oct 27 09:44:15.480852 2016] [:error] [pid 15250] [remote 10.105.40.106:200]     django.setup()
[Thu Oct 27 09:44:15.480868 2016] [:error] [pid 15250] [remote 10.105.40.106:200]   File "/home/rortega/smce_env/lib/python3.5/site-packages/django/__init__.py", line 18, in setup
[Thu Oct 27 09:44:15.480892 2016] [:error] [pid 15250] [remote 10.105.40.106:200]     apps.populate(settings.INSTALLED_APPS)
[Thu Oct 27 09:44:15.480908 2016] [:error] [pid 15250] [remote 10.105.40.106:200]   File "/home/rortega/smce_env/lib/python3.5/site-packages/django/apps/registry.py", line 78, in populate
[Thu Oct 27 09:44:15.480932 2016] [:error] [pid 15250] [remote 10.105.40.106:200]     raise RuntimeError("populate() isn't reentrant")
[Thu Oct 27 09:44:15.480958 2016] [:error] [pid 15250] [remote 10.105.40.106:200] RuntimeError: populate() isn't reentrant
[Thu Oct 27 09:44:15.561544 2016] [:error] [pid 15250] [remote 10.105.40.106:54216] mod_wsgi (pid=15250): Target WSGI script '/home/rortega/smce/smce/wsgi.py' cannot be loaded as Python module.
[Thu Oct 27 09:44:15.561571 2016] [:error] [pid 15250] [remote 10.105.40.106:54216] mod_wsgi (pid=15250): Exception occurred processing WSGI script '/home/rortega/smce/smce/wsgi.py'.
[Thu Oct 27 09:44:15.561597 2016] [:error] [pid 15250] [remote 10.105.40.106:54216] Traceback (most recent call last):
[Thu Oct 27 09:44:15.561623 2016] [:error] [pid 15250] [remote 10.105.40.106:54216]   File "/home/rortega/smce/smce/wsgi.py", line 16, in <module>
[Thu Oct 27 09:44:15.561658 2016] [:error] [pid 15250] [remote 10.105.40.106:54216]     application = get_wsgi_application()
[Thu Oct 27 09:44:15.561675 2016] [:error] [pid 15250] [remote 10.105.40.106:54216]   File "/home/rortega/smce_env/lib/python3.5/site-packages/django/core/wsgi.py", line 13, in get_wsgi_application
[Thu Oct 27 09:44:15.561703 2016] [:error] [pid 15250] [remote 10.105.40.106:54216]     django.setup()
[Thu Oct 27 09:44:15.561719 2016] [:error] [pid 15250] [remote 10.105.40.106:54216]   File "/home/rortega/smce_env/lib/python3.5/site-packages/django/__init__.py", line 18, in setup
[Thu Oct 27 09:44:15.561743 2016] [:error] [pid 15250] [remote 10.105.40.106:54216]     apps.populate(settings.INSTALLED_APPS)
[Thu Oct 27 09:44:15.561774 2016] [:error] [pid 15250] [remote 10.105.40.106:54216]   File "/home/rortega/smce_env/lib/python3.5/site-packages/django/apps/registry.py", line 78, in populate
[Thu Oct 27 09:44:15.561800 2016] [:error] [pid 15250] [remote 10.105.40.106:54216]     raise RuntimeError("populate() isn't reentrant")
[Thu Oct 27 09:44:15.561824 2016] [:error] [pid 15250] [remote 10.105.40.106:54216] RuntimeError: populate() isn't reentrant


在检查功能性之前我注意到的另一件事:

  • 执行 makemigrations 时,我的 4 个应用程序中只有一个模型文件进行了迁移,就像只有一个应用程序一样
  • python manage.py runserver 没有错误

【问题讨论】:

  • 一般情况下,当你看到这个错误时,你需要回到日志中,找到与WSGI脚本无法加载相关的第一条错误信息。这将为您提供问题的真正原因。随后的消息会有所不同,因为 Django 的几个版本发生了变化,这意味着您不能在此过程中多次尝试初始化 Django。

标签: apache python-3.x mod-wsgi centos7 django-1.9


【解决方案1】:

RuntimeError: populate() 不可重入

根据我的经验,这通常意味着 Django 项目中的某个地方存在错误。可能很难找到。另外,别忘了重启apache。

执行 makemigrations 时,我的 4 个应用程序中只有一个模型文件进行了迁移,就像只有一个应用程序一样

尝试将 makemigrations 指向特定的应用程序:

python manage.py makemigrations appname

之后不要忘记应用迁移:

python manage.py migrate

【讨论】:

  • 好的,我会为每个应用程序进行迁移。还会检查我的 django 应用程序中的所有内容。谢谢!让你知道结果
  • @Izuzvo 运气好吗?
  • 这似乎与在python2.7下运行的mod_wsgi有关。所以我在this solution 之后用 tha thag --with-python=/usr/local/bin/python3.5 重新编译了它。但它告诉我这个error: Failed to locate the Python library /usr/local/lib/libpython3.3m.so。后来我尝试使用 --enable-shared 重建 python3 但我得到了this
  • @Izuzvo 我一直处于那个位置。不确定是否是相同的原因。就我而言,这是一个服务器配置问题。
  • @Izuzvo 您是否以 root 身份构建 python3?
【解决方案2】:

对于遇到此问题的每个人来说,它可能是任何事情,例如错误的 django 配置或 de mod_wsgi 的问题。 就我而言,我需要使用 --enable-shared 标签构建 python 3。

如果你也是这种情况,可以关注this

【讨论】:

  • 也可能是由于进程启动时数据库不可用造成的。对于可以恢复的此类暂时性问题,较新的 mod_wsgi 版本有一个 startup-timeout 选项,可以为 WSGIDaemonProcess 设置。使用此设置,如果无法加载 WSGI 脚本文件,则在多次尝试后,在启动超时时间内,将重新启动进程。这样,如果出现暂时性问题并陷入可重入初始化问题,进程将被踢出并可能在下一次工作。
猜你喜欢
  • 2018-08-23
  • 1970-01-01
  • 2016-10-17
  • 2015-09-06
  • 2017-01-29
  • 2019-02-14
  • 1970-01-01
  • 2016-06-07
  • 2020-08-10
相关资源
最近更新 更多