简体   繁体   English

Django中的Python代码未使用Apache / mod_wsgi在守护程序模式下重新编译

[英]Python code in Django not recompiling in daemon mode with Apache/mod_wsgi

I am running a Django application using Apache2 with mod_wsgi in daemon mode: 我在守护程序模式下使用带有mod_wsgi的Apache2运行Django应用程序:

WSGIApplicationGroup %{GLOBAL}

WSGIDaemonProcess my_app_process
WSGIScriptAlias /my_app /var/www/my_app/wsgi.py process-group=my_app_process
WSGIScriptReloading On

Whenever I make changes to my Python code on server (I know this is highly discouraged, but I'm only using it for debugging) I keep having trouble with recompiling the code, but only in subdirectories. 每当我在服务器上更改我的Python代码时(我强烈建议不要这样做,但我仅将其用于调试),我一直在重新编译代码时遇到麻烦,但只能在子目录中进行。

Python files in the root directory of the application (ie settings.py) get recompiled nicely, but not the ones located in subdirectories (ie views.py of some app). 可以很好地重新编译应用程序根目录(即settings.py)中的Python文件,而不是位于子目录(即某些应用程序的views.py)中的Python文件。

The application directory is owned by the www-data user and the user has sufficient privileges (tested with 777). 应用程序目录归www-data用户所有,并且该用户具有足够的特权(已通过777测试)。

Restarting the Apache or touching the wsgi file only results in recompiling of the Python files in root directory of the application. 重新启动Apache或触摸wsgi文件只会导致重新编译应用程序根目录中的Python文件。

EDIT: 编辑:

I also tried adding the WSGIProcessGroup directive with no effect: 我还尝试添加WSGIProcessGroup指令,但无效:

WSGIApplicationGroup %{GLOBAL}

WSGIDaemonProcess my_app_process processes=2 threads=15
WSGIProcessGroup my_app_process
WSGIScriptAlias /my_app /var/www/my_app/wsgi.py
WSGIScriptReloading On

Also, using the code provided here I have concluded I am, in fact, running in daemon mode. 另外,使用这里提供的代码,我得出的结论是,我实际上是在守护程序模式下运行。

EDIT #2 编辑#2

Added Apache log from restart: 从重新启动添加了Apache日志:

[Fri Jan 06 12:03:06.309060 2017] [wsgi:warn] [pid 28372:tid 139790316758912] mod_wsgi: Compiled for Python/2.7.8.
[Fri Jan 06 12:03:06.309186 2017] [wsgi:warn] [pid 28372:tid 139790316758912] mod_wsgi: Runtime using Python/2.7.9.
[Fri Jan 06 12:03:06.309876 2017] [wsgi:info] [pid 28375:tid 139790316758912] mod_wsgi (pid=28375): Starting process 'my_app' with uid=33, gid=33 and threads=15.
[Fri Jan 06 12:03:06.310193 2017] [wsgi:info] [pid 28375:tid 139790316758912] mod_wsgi (pid=28375): Initializing Python.
[Fri Jan 06 12:03:06.310246 2017] [wsgi:info] [pid 28376:tid 139790316758912] mod_wsgi (pid=28376): Starting process 'my_app_2' with uid=33, gid=33 and threads=15.
[Fri Jan 06 12:03:06.310531 2017] [wsgi:info] [pid 28377:tid 139790316758912] mod_wsgi (pid=28377): Starting process 'my_app_3' with uid=33, gid=33 and threads=15.
[Fri Jan 06 12:03:06.310607 2017] [wsgi:info] [pid 28376:tid 139790316758912] mod_wsgi (pid=28376): Initializing Python.
[Fri Jan 06 12:03:06.310855 2017] [wsgi:info] [pid 28377:tid 139790316758912] mod_wsgi (pid=28377): Initializing Python.
[Fri Jan 06 12:03:06.311029 2017] [mpm_event:notice] [pid 28372:tid 139790316758912] AH00489: Apache/2.4.10 (Debian) mod_wsgi/4.3.0 Python/2.7.9 configured -- resuming normal operations
[Fri Jan 06 12:03:06.311057 2017] [mpm_event:info] [pid 28372:tid 139790316758912] AH00490: Server built: Sep 15 2016 20:44:43
[Fri Jan 06 12:03:06.311071 2017] [core:notice] [pid 28372:tid 139790316758912] AH00094: Command line: '/usr/sbin/apache2'
[Fri Jan 06 12:03:06.311379 2017] [wsgi:info] [pid 28379:tid 139790316758912] mod_wsgi (pid=28379): Initializing Python.
[Fri Jan 06 12:03:06.311507 2017] [wsgi:info] [pid 28378:tid 139790316758912] mod_wsgi (pid=28378): Initializing Python.
[Fri Jan 06 12:03:06.324667 2017] [wsgi:info] [pid 28377:tid 139790316758912] mod_wsgi (pid=28377): Attach interpreter ''.
[Fri Jan 06 12:03:06.324671 2017] [wsgi:info] [pid 28376:tid 139790316758912] mod_wsgi (pid=28376): Attach interpreter ''.
[Fri Jan 06 12:03:06.324843 2017] [wsgi:info] [pid 28377:tid 139790316758912] mod_wsgi (pid=28377): Adding '/var/anaconda2/lib/python2.7/site-packages' to path.
[Fri Jan 06 12:03:06.324864 2017] [wsgi:info] [pid 28376:tid 139790316758912] mod_wsgi (pid=28376): Adding '/var/anaconda2/lib/python2.7/site-packages' to path.
[Fri Jan 06 12:03:06.324988 2017] [wsgi:info] [pid 28378:tid 139790316758912] mod_wsgi (pid=28378): Attach interpreter ''.
[Fri Jan 06 12:03:06.329741 2017] [wsgi:info] [pid 28379:tid 139790316758912] mod_wsgi (pid=28379): Attach interpreter ''.
[Fri Jan 06 12:03:06.335879 2017] [wsgi:info] [pid 28375:tid 139790316758912] mod_wsgi (pid=28375): Attach interpreter ''.
[Fri Jan 06 12:03:06.336042 2017] [wsgi:info] [pid 28375:tid 139790316758912] mod_wsgi (pid=28375): Adding '/var/anaconda2/lib/python2.7/site-packages' to path.
[Fri Jan 06 12:03:13.598083 2017] [wsgi:info] [pid 28375:tid 139790204262144] [remote 10.6.6.58:512] mod_wsgi (pid=28375, process='my_app', application=''): Loading WSGI script '/var/www/my_app/wsgi.py'.

Added Apache log from touching the WSGI script: 通过触摸WSGI脚本添加了Apache日志:

[Fri Jan 06 12:12:28.348075 2017] [wsgi:info] [pid 28835:tid 139790316758912] mod_wsgi (pid=28835): Shutdown requested 'my_app'.
[Fri Jan 06 12:12:28.348217 2017] [wsgi:info] [pid 28835:tid 139790316758912] mod_wsgi (pid=28835): Stopping process 'my_app'.
[Fri Jan 06 12:12:28.348237 2017] [wsgi:info] [pid 28835:tid 139790316758912] mod_wsgi (pid=28835): Destroying interpreters.
[Fri Jan 06 12:12:28.348244 2017] [wsgi:info] [pid 28835:tid 139790316758912] mod_wsgi (pid=28835): Cleanup interpreter ''.
[Fri Jan 06 12:12:28.348954 2017] [wsgi:info] [pid 28835:tid 139790316758912] mod_wsgi (pid=28835): Terminating Python.
[Fri Jan 06 12:12:28.469333 2017] [wsgi:info] [pid 28835:tid 139790316758912] mod_wsgi (pid=28835): Python has shutdown.
[Fri Jan 06 12:12:28.469366 2017] [wsgi:info] [pid 28835:tid 139790316758912] mod_wsgi (pid=28835): Exiting process 'my_app'.
[Fri Jan 06 12:12:29.129042 2017] [wsgi:info] [pid 28372:tid 139790316758912] mod_wsgi (pid=28835): Process 'my_app' has died, deregister and restart it.
[Fri Jan 06 12:12:29.129094 2017] [wsgi:info] [pid 28372:tid 139790316758912] mod_wsgi (pid=28835): Process 'my_app' terminated normally, exit code 0
[Fri Jan 06 12:12:29.129099 2017] [wsgi:info] [pid 28372:tid 139790316758912] mod_wsgi (pid=28835): Process 'my_app' has been deregistered and will no longer be monitored.
[Fri Jan 06 12:12:29.129764 2017] [wsgi:info] [pid 28917:tid 139790316758912] mod_wsgi (pid=28917): Starting process 'my_app' with uid=33, gid=33 and threads=15.
[Fri Jan 06 12:12:29.130173 2017] [wsgi:info] [pid 28917:tid 139790316758912] mod_wsgi (pid=28917): Initializing Python.
[Fri Jan 06 12:12:29.144492 2017] [wsgi:info] [pid 28917:tid 139790316758912] mod_wsgi (pid=28917): Attach interpreter ''.
[Fri Jan 06 12:12:29.144687 2017] [wsgi:info] [pid 28917:tid 139790316758912] mod_wsgi (pid=28917): Adding '/var/anaconda2/lib/python2.7/site-packages' to path.
[Fri Jan 06 12:12:29.147279 2017] [wsgi:info] [pid 28917:tid 139790204262144] [remote 10.6.6.58:512] mod_wsgi (pid=28917, process='my_app', application=''): Loading WSGI script '/var/www/my_app/wsgi.py'.

It looks like your missing the WSGIProcessGroup directive: 好像您缺少WSGIProcessGroup指令:

https://modwsgi.readthedocs.io/en/develop/user-guides/quick-configuration-guide.html#delegation-to-daemon-process https://modwsgi.readthedocs.io/en/develop/user-guides/quick-configuration-guide.html#delegation-to-daemon-process

To make use of daemon mode for WSGI applications hosted within a specific site, the WSGIDaemonProcess and WSGIProcessGroup directives would need to be defined. 要对特定站点中托管的WSGI应用程序使用守护程序模式,则需要定义WSGIDaemonProcess和WSGIProcessGroup指令。 For example, to setup a daemon process group containing two multithreaded process one could use: WSGIDaemonProcess example.com processes=2 threads=15 WSGIProcessGroup example.com 例如,要设置一个包含两个多线程进程的守护进程组,可以使用:WSGIDaemonProcess example.com process = 2线程= 15 WSGIProcessGroup example.com

This being said, unless the issues you need to debug are specific to your deployment configuration, you'd be better working locally with the builtin dev server 话虽这么说,除非您需要调试的问题是特定于您的部署配置的,否则您最好在本地使用内置开发服务器进行工作

It would be by chance that you are seeing changes due to wrongly running in embedded mode, which probably means new process gets request if using prefork MPM. 您可能会偶然发现由于错误地以嵌入式模式运行而导致的更改,这可能意味着如果使用prefork MPM,则新流程会得到请求。

In addition to properly setting up embedded mode, which is is preferred, read the documentation about source code reloading at: 除了正确设置嵌入式模式(首选)之外,还可以在以下位置阅读有关重新加载源代码的文档:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM