Browse Source

Imporves InotifyMonitor event handling

Mher Movsisyan 13 years ago
parent
commit
917be2f207
1 changed files with 14 additions and 8 deletions
  1. 14 8
      celery/worker/autoreload.py

+ 14 - 8
celery/worker/autoreload.py

@@ -148,23 +148,29 @@ class InotifyMonitor(_ProcessEvent):
         assert pyinotify
         self._modules = modules
         self._on_change = on_change
+        self._wm = None
+        self._notifier = None
 
     def start(self):
         try:
             self._wm = pyinotify.WatchManager()
-            self._notifier = pyinotify.Notifier(self._wm)
+            self._notifier = pyinotify.Notifier(self._wm, self)
             for m in self._modules:
-                self._wm.add_watch(m, pyinotify.IN_MODIFY)
+                self._wm.add_watch(m, pyinotify.IN_MODIFY|pyinotify.IN_ATTRIB)
             self._notifier.loop()
         finally:
-            self.close()
+            if self._wm:
+                self._wm.close()
+                # Notifier.close is called at the end of Notifier.loop
+                self._wm = self._notifier = None
 
-    def close(self):
-        self._notifier.stop()
-        self._wm.close()
+    def stop(self):
+        pass
+
+    def process_(self, event):
+        self.on_change([event.path])
 
-    def process_IN_MODIFY(self, event):
-        self.on_change(event.pathname)
+    process_IN_ATTRIB = process_IN_MODIFY = process_
 
     def on_change(self, modified):
         if self._on_change: