Skip to content

Commit

Permalink
Allow deferred start in FSMonitorThread (e.g. in order to add directo…
Browse files Browse the repository at this point in the history
…ries and then start)

Added **kwargs to FSMonitorThread.add_dir_watch() and .add_file_watch(), in particular since FSMonitor.add_dir_watch() has a recursive argument
  • Loading branch information
jason-s authored and jason-sachs committed Apr 17, 2015
1 parent ecb2533 commit d260eae
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions fsmonitor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,27 @@
from .polling import FSMonitor

class FSMonitorThread(threading.Thread):
def __init__(self, callback=None):
def __init__(self, callback=None, autostart=True):
threading.Thread.__init__(self)
self.monitor = FSMonitor()
self.callback = callback
self._running = True
self._events = []
self._events_lock = threading.Lock()
self.daemon = True
self.start()
if autostart:
self.start()
else:
self._running = False

def add_dir_watch(self, path, flags=FSEvent.All, user=None):
return self.monitor.add_dir_watch(path, flags=flags, user=user)
def start(self):
self._running = True
super(FSMonitorThread, self).start()

def add_dir_watch(self, path, flags=FSEvent.All, user=None, **kwargs):
return self.monitor.add_dir_watch(path, flags=flags, user=user, **kwargs)

def add_file_watch(self, path, flags=FSEvent.All, user=None):
return self.monitor.add_file_watch(path, flags=flags, user=user)
def add_file_watch(self, path, flags=FSEvent.All, user=None, **kwargs):
return self.monitor.add_file_watch(path, flags=flags, user=user, **kwargs)

def remove_watch(self, watch):
self.monitor.remove_watch(watch)
Expand Down

0 comments on commit d260eae

Please sign in to comment.