From e19f9e16971741cef48571d09d2eeeb061ce7e0b Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Wed, 16 Apr 2014 00:47:43 -0400 Subject: [PATCH] BF(?): stop/join notifier only if defined Somehow on that elderly squeeze Debian sparc box, I got error that self.__notifier was not defined. So first I did define it now in the constructor, but mystery remains how come it was not defined -- wasn"t run() then run (where it is defined)? Anyways -- conditioning on it being defined might be safer may be? Not sure (need to go to sleep) if with this change but on this box I also run from time to time either into stalling of fail2ban-testcases and refusing to exit normally or ====================================================================== ERROR: test_move_into_file_after_removed (testcases.filtertestcase.MonitorFailures(/tmp/monitorfailures_FilterPyinotifypcHmMJfail2ban)) ---------------------------------------------------------------------- Traceback (most recent call last): File "/home/yoh/deb/gits/fail2ban/testcases/filtertestcase.py", line 473, in tearDown self.filter.stop() File "/home/yoh/deb/gits/fail2ban/server/filterpyinotify.py", line 196, in stop self.__notifier.stop() File "/usr/lib/pymodules/python2.6/pyinotify.py", line 1315, in stop threading.Thread.join(self) File "/usr/lib/python2.6/threading.py", line 633, in join raise RuntimeError("cannot join thread before it is started") RuntimeError: cannot join thread before it is started that is with pyinotify 0.8.9-1 so could quite be "related" to its age. --- server/filterpyinotify.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/server/filterpyinotify.py b/server/filterpyinotify.py index 68675df4..8a9e4529 100644 --- a/server/filterpyinotify.py +++ b/server/filterpyinotify.py @@ -69,6 +69,7 @@ class FilterPyinotify(FileFilter): # Pyinotify watch manager self.__monitor = pyinotify.WatchManager() self.__watches = dict() + self.__notifier = None logSys.debug("Created FilterPyinotify") @@ -190,9 +191,10 @@ class FilterPyinotify(FileFilter): def stop(self): super(FilterPyinotify, self).stop() - # Stop the notifier thread - self.__notifier.stop() - self.__notifier.join() # to not exit before notifier does + # Stop the notifier thread if it was ran and notifier was created + if self.__notifier is not None: + self.__notifier.stop() + self.__notifier.join() # to not exit before notifier does self.__cleanup() # for pedantic ones ##