2017-01-11 1 views
0

Nous utilisons django (1.7.5) avec mod_wsgi sous apache2 dans le serveur redhat, et essayons d'utiliser watchdog pour surveiller les fichiers.Le module python watchdog ne fonctionne pas avec django/mod_wsgi sous le serveur redhat

Il fonctionne très bien localement en utilisant la commande python manager.py runserver, alors que l'événement ne triggerred en mode wsgi quand je déploie dans l'environnement produit

 
# wsgi.py 
from django.core.wsgi import get_wsgi_application 
application = get_wsgi_application() 

LOGGER.debug("Starting to watch for config file changes.") 
fw = FileWatcher() 
 
# filewatcher 
path = settings.PROJECT_ROOT 
filename = 'config.json' 
class ConfigHandler(FileSystemEventHandler): 
    def on_modified(self, event): 
     if not event.is_directory and event.src_path.endswith(filename): 
      LOGGER.debug("The config has changed!, Reloading") 

class FileWatcher(object): 

    _instance = None 
    _watching = False 

    def __new__(cls, *args, **kwargs): 
     if not cls._instance: 
      LOGGER.debug("Creating new FileWatcher") 
      cls._instance = super(FileWatcher, cls).__new__(cls, *args, **kwargs) 

      cls.start_watching() 

     return cls._instance 

    @classmethod 
    def start_watching(cls): 
     if not cls._watching: 
      LOGGER.debug("Starting to monitor the file: %s", 
         os.path.join(path, filename)) 
      event_handler = ConfigHandler() 
      observer = Observer() 
      observer.schedule(event_handler, path=path, recursive=False) 
      observer.start() 

      cls._watching = True 

Répondre

0

trouvé la cause de la route, l'observateur par défaut (inotify.InotifyObserver) doesn « t travail dans le vieux serveur RedHat avec le vieux noyau linux

Il est indiqué dans http://pythonhosted.org/watchdog/api.html#module-watchdog.observers

 
inotify.InotifyObserver Linux 2.6.13+ inotify(7) based observer 
polling.PollingObserver Any fallback implementation 

donc je l'ai changé générique un

 
    from watchdog.observers.polling import PollingObserver 
    # http://pythonhosted.org/watchdog/api.html#module-watchdog.observers 
    observer = PollingObserver()