From cebacb15e6d6c1d67a860876392124f4c7b924de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Fri, 1 Jun 2018 14:06:40 +0200 Subject: [PATCH] Use power of LazyInitialise to replace ObserverMixin.__init__() --- lib/tfw/components/directory_monitor.py | 1 - lib/tfw/components/history_monitor.py | 1 - lib/tfw/components/log_monitor.py | 1 - lib/tfw/mixins/observer_mixin.py | 7 +++++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/tfw/components/directory_monitor.py b/lib/tfw/components/directory_monitor.py index ba423be..3ad6732 100644 --- a/lib/tfw/components/directory_monitor.py +++ b/lib/tfw/components/directory_monitor.py @@ -16,7 +16,6 @@ LOG = logging.getLogger(__name__) class DirectoryMonitor(ObserverMixin): def __init__(self, directories): - ObserverMixin.__init__(self) self.eventhandler = IdeReloadWatchdogEventHandler() for directory in directories: self.observer.schedule(self.eventhandler, directory, recursive=True) diff --git a/lib/tfw/components/history_monitor.py b/lib/tfw/components/history_monitor.py index d5586a7..67bfc3b 100644 --- a/lib/tfw/components/history_monitor.py +++ b/lib/tfw/components/history_monitor.py @@ -37,7 +37,6 @@ class HistoryMonitor(CallbackMixin, ObserverMixin, ABC): """ def __init__(self, histfile): CallbackMixin.__init__(self) - ObserverMixin.__init__(self) self.histfile = histfile self._history = [] self._last_length = len(self._history) diff --git a/lib/tfw/components/log_monitor.py b/lib/tfw/components/log_monitor.py index d7672d1..d8d1825 100644 --- a/lib/tfw/components/log_monitor.py +++ b/lib/tfw/components/log_monitor.py @@ -14,7 +14,6 @@ from tfw.mixins import ObserverMixin, SupervisorLogMixin class LogMonitor(ObserverMixin): def __init__(self, process_name, log_tail=0): self.prevent_log_recursion() - ObserverMixin.__init__(self) event_handler = SendLogWatchdogEventHandler(process_name, log_tail=log_tail) self.observer.schedule( event_handler, diff --git a/lib/tfw/mixins/observer_mixin.py b/lib/tfw/mixins/observer_mixin.py index 4101d96..198c405 100644 --- a/lib/tfw/mixins/observer_mixin.py +++ b/lib/tfw/mixins/observer_mixin.py @@ -3,10 +3,13 @@ from watchdog.observers import Observer +from tfw.decorators import LazyInitialise + class ObserverMixin: - def __init__(self): - self.observer = Observer() + @LazyInitialise + def observer(self): + return Observer() def watch(self): self.observer.start()