try not creating a duplicate Observer

This commit is contained in:
Jean-Paul Calderone 2019-02-27 14:54:45 -05:00
parent 679b9a93c1
commit 725c85b2f4
2 changed files with 10 additions and 4 deletions

View File

@ -1144,8 +1144,14 @@ class Uploader(QueueMixin):
| self._inotify.IN_ONLYDIR
| IN_EXCL_UNLINK
)
self._notifier.watch(self._local_filepath, mask=self.mask, callbacks=[self._notify],
recursive=True)
def _add_watch(self):
self._notifier.watch(
self._local_filepath,
mask=self.mask,
callbacks=[self._notify],
recursive=True,
)
def start_monitoring(self):
action = START_MONITORING(**self._log_fields)
@ -1153,6 +1159,7 @@ class Uploader(QueueMixin):
d = DeferredContext(defer.succeed(None))
d.addCallback(lambda ign: self._notifier.startReading())
d.addCallback(lambda ign: self._add_watch())
d.addCallback(lambda ign: self._count('dirs_monitored'))
d.addBoth(self._call_hook, 'started')
return d.addActionFinish()

View File

@ -161,7 +161,6 @@ class INotify(PollMixin):
def __init__(self):
self._pending_delay = 1.0
self.recursive_includes_new_subdirectories = False
self._observer = Observer(timeout=self._pending_delay)
self._callbacks = {}
self._watches = {}
self._state = NOT_STARTED
@ -170,7 +169,6 @@ class INotify(PollMixin):
Message.log(message_type=u"watchdog:inotify:set-pending-delay", delay=delay)
assert self._state != STARTED
self._pending_delay = delay
self._observer = Observer(timeout=self._pending_delay)
def startReading(self):
with start_action(action_type=u"watchdog:inotify:start-reading"):
@ -179,6 +177,7 @@ class INotify(PollMixin):
# XXX twisted.internet.inotify doesn't require watches to
# be set before startReading is called.
# _assert(len(self._callbacks) != 0, "no watch set")
self._observer = Observer(timeout=self._pending_delay)
self._observer.start()
self._state = STARTED
except: