From 32e3c2860d5a4950459228993b32b77685e85481 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Tue, 29 May 2018 10:55:55 +0200 Subject: [PATCH] Fix inotify event logs triggering themselves (infinite log recursion) --- lib/tfw/components/log_monitor.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/tfw/components/log_monitor.py b/lib/tfw/components/log_monitor.py index db66132..e3b5e2b 100644 --- a/lib/tfw/components/log_monitor.py +++ b/lib/tfw/components/log_monitor.py @@ -1,6 +1,7 @@ # Copyright (C) 2018 Avatao.com Innovative Learning Kft. # All Rights Reserved. See LICENSE file for details. +import logging from os.path import dirname from watchdog.events import PatternMatchingEventHandler as PatternMatchingWatchdogEventHandler @@ -12,6 +13,7 @@ from tfw.mixins import ObserverMixin, SupervisorLogMixin class LogMonitor(ObserverMixin): def __init__(self, process_name): + self.prevent_log_recursion() ObserverMixin.__init__(self) event_handler = SendLogWatchdogEventHandler(process_name) self.observer.schedule( @@ -19,6 +21,11 @@ class LogMonitor(ObserverMixin): event_handler.path ) + @staticmethod + def prevent_log_recursion(): + # This is done to prevent inotify event logs triggering themselves (infinite log recursion) + logging.getLogger('watchdog.observers.inotify_buffer').propagate = False + class SendLogWatchdogEventHandler(PatternMatchingWatchdogEventHandler, SupervisorLogMixin): def __init__(self, process_name):