【问题标题】:python watchdog module doesn't work with django/mod_wsgi under redhat serverpython看门狗模块在redhat服务器下不能与django/mod_wsgi一起使用
【发布时间】:2017-05-25 21:31:27
【问题描述】:
我们在redhat服务器的apache2下使用django(1.7.5)和mod_wsgi,并尝试使用看门狗来监控文件。
使用python manager.py runserver 命令在本地运行良好,而当我将其部署到产品环境中时,该事件不会在 wsgi 模式下触发
#wsgi.py
从 django.core.wsgi 导入 get_wsgi_application
应用程序 = get_wsgi_application()
LOGGER.debug("开始监视配置文件更改。")
fw = FileWatcher()
# 文件观察器
路径 = settings.PROJECT_ROOT
文件名 = 'config.json'
类 ConfigHandler(FileSystemEventHandler):
def on_modified(自我,事件):
如果不是 event.is_directory 和 event.src_path.endswith(filename):
LOGGER.debug("配置已更改!,正在重新加载")
类 FileWatcher(对象):
_instance = 无
_watching = 假
def __new__(cls, *args, **kwargs):
如果不是 cls._instance:
LOGGER.debug("创建新的 FileWatcher")
cls._instance = super(FileWatcher, cls).__new__(cls, *args, **kwargs)
cls.start_watching()
返回 cls._instance
@classmethod
def start_watching(cls):
如果不是 cls._watching:
LOGGER.debug("开始监控文件:%s",
os.path.join(路径,文件名))
event_handler = ConfigHandler()
观察者 = 观察者()
observer.schedule(event_handler, path=path, recursive=False)
观察者.start()
cls._watching = 真
【问题讨论】:
-
你能分享你的代码,你是如何在本地和 wsgi 中将 watchdog 集成到 django 项目中的吗?从上面的代码中,我无法了解您的 FileWatcher 类在哪里初始化并与 views.py 一起使用。
标签:
python
django
python-2.7
mod-wsgi