Django 1.7在mod-wsgi上的代码更改监视故障 [英] Code change monitoring malfunctioning with Django 1.7 on mod-wsgi

查看:45
本文介绍了Django 1.7在mod-wsgi上的代码更改监视故障的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我在mod_wsgi中运行Django 1.7的所有站点上遇到的一个问题.问题的核心是,如果在本地开发时,我向代码库中引入了致命错误,然后对其进行了纠正,则代码监视脚本将无法检测到该纠正.

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.

我使用 Graham Dumpleton的monitor.py脚本以在我进行本地开发时检测对代码库的更改(我使用apache而不是Django开发服务器).

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).

它总是在Django< = 1.6中起作用,但是在Django 1.7中,出现以下错误:

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

令人烦恼的是,如果我更正错误,monitor.py不会检测到更改,因此我必须重新启动apache或触摸另一个已加载的文件(例如设置文件).

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).

我认为这是因为重新加载代码仅监视导入的文件(即sys.modules)"(

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.

推荐答案

我不确定您的部署过程是什么,也不知道您的生产操作系统是什么,但是在Linux/Ubuntu世界中,有一个名为pyclean的OS命令.在我的Django/Python部署脚本中(通常通过结构),我发出命令"pyclean".在项目根目录中.该脚本递归删除当前文件夹中开始的所有.pyc文件.我希望这会有所帮助.

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.

这篇关于Django 1.7在mod-wsgi上的代码更改监视故障的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆