From 49c32d49079d60d8a85c5801993a6ad35022eb93 Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Fri, 13 Dec 2013 18:58:17 +1100 Subject: [PATCH] Dnotify: possible fix for multiple signals. I seem to lose signals sometimes. This catches signals while handling signals and serialised them. --- lib/dnotify.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/lib/dnotify.py b/lib/dnotify.py index 8ec6cb8..9ba360f 100644 --- a/lib/dnotify.py +++ b/lib/dnotify.py @@ -28,11 +28,22 @@ 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): -- 2.39.5