From 35fc563a6fde9274b5fa14b1259b64fc18c3c768 Mon Sep 17 00:00:00 2001 From: Jean-Paul Calderone Date: Thu, 7 Mar 2019 11:42:12 -0500 Subject: [PATCH] Attempt to work-around watchdog bug --- src/allmydata/watchdog/_watchdog_541.py | 16 ++++++++++++++++ src/allmydata/watchdog/inotify.py | 3 +++ 2 files changed, 19 insertions(+) create mode 100644 src/allmydata/watchdog/_watchdog_541.py diff --git a/src/allmydata/watchdog/_watchdog_541.py b/src/allmydata/watchdog/_watchdog_541.py new file mode 100644 index 000000000..87686ce6d --- /dev/null +++ b/src/allmydata/watchdog/_watchdog_541.py @@ -0,0 +1,16 @@ +""" +Hotfix for https://github.com/gorakhargosh/watchdog/issues/541 +""" + +from watchdog.observers.fsevents import FSEventsEmitter + +# The class object has already been bundled up in the default arguments to +# FSEventsObserver.__init__. So mutate the class object (instead of replacing +# it with a safer version). +original_on_thread_stop = FSEventsEmitter.on_thread_stop +def safe_on_thread_stop(self): + if self.is_alive(): + return original_on_thread_stop(self) + +def patch(): + FSEventsEmitter.on_thread_stop = safe_on_thread_stop diff --git a/src/allmydata/watchdog/inotify.py b/src/allmydata/watchdog/inotify.py index 5db35d9dd..4b717aae6 100644 --- a/src/allmydata/watchdog/inotify.py +++ b/src/allmydata/watchdog/inotify.py @@ -53,6 +53,9 @@ from ..util.eliotutil import ( validateInstanceOf, ) +import ._watchdog_541 +_watchdog_541.patch() + NOT_STARTED = "NOT_STARTED" STARTED = "STARTED" STOPPING = "STOPPING"