Code change monitoring malfunctioning with Django 1.7 on mod-wsgi

ぃ、小莉子 提交于 2019-12-03 13:10:44

问题


This is an issue that I've encountered on all my sites that are running Django 1.7 in mod_wsgi. The nub of the issue is that if, while developing locally, I introduce a fatal error into the codebase, and then subsequently correct it, the code monitoring script doesn't detect the correction.

I use Graham Dumpleton's monitor.py script to detect changes to the codebase when I'm developing locally (I use apache rather than the Django development server).

It always used to work in Django <= 1.6, but in Django 1.7 I get the following error:

File "/home/me/.virtualenvs/myvirtualenv/lib/python2.7/site-packages/django/core/wsgi.py", line 14, in get_wsgi_application
    django.setup()
File "/home/me/virtualenvs/myvirtualenv/lib/python2.7/site-packages/django/__init__.py", line 21, in setup
    apps.populate(settings.INSTALLED_APPS)
File "/home/me/.virtualenvs/myvirtualenv/lib/python2.7/site-packages/django/apps/registry.py", line 78, in populate
    raise RuntimeError("populate() isn't reentrant")
RuntimeError: populate() isn't reentrant

The irritating thing is that if I correct the error, monitor.py doesn't detect the change, so I have to either restart apache, or touch another file that was already loaded (e.g. the settings file).

I think this is because of the fact that "the reloading code only monitors imported files (aka sys.modules)" (source). So because the incorrect file wasn't successfully imported, monitor.py doesn't know to restart the process.


回答1:


I am not sure what your deployment process is nor your production operating system, but in the Linux/Ubuntu world there is a OS command called pyclean. During my Django/Python deployment scripts (usually via fabric) I issue the command "pyclean ." in the project root. This script recursively deletes all .pyc files starting in the current folder. I hope this helps.



来源:https://stackoverflow.com/questions/27232732/code-change-monitoring-malfunctioning-with-django-1-7-on-mod-wsgi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!