]> git.neil.brown.name Git - plato.git/commitdiff
Dnotify: possible fix for multiple signals.
authorNeilBrown <neilb@suse.de>
Fri, 13 Dec 2013 07:58:17 +0000 (18:58 +1100)
committerNeilBrown <neilb@suse.de>
Fri, 13 Dec 2013 07:58:17 +0000 (18:58 +1100)
I seem to lose signals sometimes.
This catches signals while handling signals and serialised them.

lib/dnotify.py

index 8ec6cb8af9c7d638127ff58c2023319b2f70de6a..9ba360ff2d23690d1e62983bd7a4fc6dfdbc00cd 100644 (file)
 import os, fcntl, signal
 
 dirlist = []
+active = False
+again = False
 def notified(sig, stack):
-    for d in dirlist:
-        fcntl.fcntl(d.fd, fcntl.F_NOTIFY, (fcntl.DN_MODIFY|fcntl.DN_RENAME|
-                                           fcntl.DN_CREATE|fcntl.DN_DELETE))
-        d.check()
+    global active, again
+    if active:
+        again = True
+        return
+    again = True
+    while again:
+        active = True
+        again = False
+        for d in dirlist:
+            fcntl.fcntl(d.fd, fcntl.F_NOTIFY, (fcntl.DN_MODIFY|fcntl.DN_RENAME|
+                                               fcntl.DN_CREATE|fcntl.DN_DELETE))
+            d.check()
+        active = False
 
 class dir():
     def __init__(self, dname):
@@ -49,6 +60,7 @@ class dir():
     def watch(self, fname, callback):
         f = file(os.path.join(self.dname, fname), callback)
         self.files.append(f)
+        f.check()
         return f
 
     def watchall(self, callback):