From 44df95a434834376c59ea816d023b59f78d14540 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Mon, 28 May 2018 14:32:11 +0200 Subject: [PATCH 01/14] Refactor supervisor logging logic to separate mixin --- .../components/process_managing_event_handler.py | 4 ++-- lib/tfw/mixins/__init__.py | 2 +- lib/tfw/mixins/supervisor_mixin.py | 14 +++++++++----- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/tfw/components/process_managing_event_handler.py b/lib/tfw/components/process_managing_event_handler.py index a028334..1873dcf 100644 --- a/lib/tfw/components/process_managing_event_handler.py +++ b/lib/tfw/components/process_managing_event_handler.py @@ -4,14 +4,14 @@ from xmlrpc.client import Fault as SupervisorFault from tfw import EventHandlerBase -from tfw.mixins import SupervisorMixin +from tfw.mixins import SupervisorMixin, SupervisorLogMixin from tfw.config.logs import logging from .directory_monitor import with_monitor_paused LOG = logging.getLogger(__name__) -class ProcessManager(SupervisorMixin): +class ProcessManager(SupervisorMixin, SupervisorLogMixin): def __init__(self): self.commands = {'start': self.start_process, 'stop': self.stop_process, diff --git a/lib/tfw/mixins/__init__.py b/lib/tfw/mixins/__init__.py index 60e67fc..58915ca 100644 --- a/lib/tfw/mixins/__init__.py +++ b/lib/tfw/mixins/__init__.py @@ -1,7 +1,7 @@ # Copyright (C) 2018 Avatao.com Innovative Learning Kft. # All Rights Reserved. See LICENSE file for details. -from .supervisor_mixin import SupervisorMixin +from .supervisor_mixin import SupervisorMixin, SupervisorLogMixin from .callback_mixin import CallbackMixin from .observer_mixin import ObserverMixin from .monitor_manager_mixin import MonitorManagerMixin diff --git a/lib/tfw/mixins/supervisor_mixin.py b/lib/tfw/mixins/supervisor_mixin.py index a95b769..3df6b48 100644 --- a/lib/tfw/mixins/supervisor_mixin.py +++ b/lib/tfw/mixins/supervisor_mixin.py @@ -9,9 +9,11 @@ from os import remove from tfw.config import TFWENV -class SupervisorMixin: +class SupervisorBaseMixin: supervisor = xmlrpc.client.ServerProxy(TFWENV.SUPERVISOR_HTTP_URI).supervisor + +class SupervisorMixin(SupervisorBaseMixin): def stop_process(self, process_name): with suppress(SupervisorFault): self.supervisor.stopProcess(process_name) @@ -19,6 +21,12 @@ class SupervisorMixin: def start_process(self, process_name): self.supervisor.startProcess(process_name) + def restart_process(self, process_name): + self.stop_process(process_name) + self.start_process(process_name) + + +class SupervisorLogMixin(SupervisorBaseMixin): def read_log_stdout(self, process_name): return self._read_log_internal(self.supervisor.readProcessStdoutLog, process_name) @@ -34,7 +42,3 @@ class SupervisorMixin: for logfile in ('stdout_logfile', 'stderr_logfile'): remove(self.supervisor.getProcessInfo(process_name)[logfile]) self.supervisor.clearProcessLogs(process_name) - - def restart_process(self, process_name): - self.stop_process(process_name) - self.start_process(process_name) From 1a93dad562c9a401bcc7947e95e2c73f06ea14e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Mon, 28 May 2018 15:02:53 +0200 Subject: [PATCH 02/14] Separate log clearing from reading --- .../process_managing_event_handler.py | 17 ++++++++++------- lib/tfw/mixins/supervisor_mixin.py | 13 ++++--------- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/lib/tfw/components/process_managing_event_handler.py b/lib/tfw/components/process_managing_event_handler.py index 1873dcf..0685b48 100644 --- a/lib/tfw/components/process_managing_event_handler.py +++ b/lib/tfw/components/process_managing_event_handler.py @@ -44,12 +44,15 @@ class ProcessManagingEventHandler(EventHandlerBase): def handle_event(self, message): try: data = message['data'] - self.processmanager(data['command'], data['process_name']) - message['data']['log'] = self.processmanager.read_log_stdout(message['data']['process_name']) - return message + try: + self.processmanager(data['command'], data['process_name']) + message['data']['log'] = self.processmanager.read_stdout(data['process_name']) + return message + except SupervisorFault as fault: + message['data']['error'] = fault.faultString + message['data']['log'] = self.processmanager.read_stderr(data['process_name']) + return message + finally: + self.processmanager.clear_logs(data['process_name']) except KeyError: LOG.error('IGNORING MESSAGE: Invalid message received: %s', message) - except SupervisorFault as fault: - message['data']['error'] = fault.faultString - message['data']['log'] = self.processmanager.read_log_stderr(message['data']['process_name']) - return message diff --git a/lib/tfw/mixins/supervisor_mixin.py b/lib/tfw/mixins/supervisor_mixin.py index 3df6b48..4586e85 100644 --- a/lib/tfw/mixins/supervisor_mixin.py +++ b/lib/tfw/mixins/supervisor_mixin.py @@ -27,16 +27,11 @@ class SupervisorMixin(SupervisorBaseMixin): class SupervisorLogMixin(SupervisorBaseMixin): - def read_log_stdout(self, process_name): - return self._read_log_internal(self.supervisor.readProcessStdoutLog, process_name) + def read_stdout(self, process_name): + return self.supervisor.readProcessStdoutLog(process_name, 0, 0) - def read_log_stderr(self, process_name): - return self._read_log_internal(self.supervisor.readProcessStderrLog, process_name) - - def _read_log_internal(self, read_method, process_name): - log = read_method(process_name, 0, 0) - self.clear_logs(process_name) - return log + def read_stderr(self, process_name): + return self.supervisor.readProcessStderrLog(process_name, 0, 0) def clear_logs(self, process_name): for logfile in ('stdout_logfile', 'stderr_logfile'): From 9723f98950ff643c3117828382e1c869b92c34b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Mon, 28 May 2018 16:36:59 +0200 Subject: [PATCH 03/14] Rework ProcessManagingEH log API --- lib/tfw/components/process_managing_event_handler.py | 7 +++---- lib/tfw/mixins/supervisor_mixin.py | 5 ++++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/tfw/components/process_managing_event_handler.py b/lib/tfw/components/process_managing_event_handler.py index 0685b48..2044a38 100644 --- a/lib/tfw/components/process_managing_event_handler.py +++ b/lib/tfw/components/process_managing_event_handler.py @@ -46,13 +46,12 @@ class ProcessManagingEventHandler(EventHandlerBase): data = message['data'] try: self.processmanager(data['command'], data['process_name']) - message['data']['log'] = self.processmanager.read_stdout(data['process_name']) - return message except SupervisorFault as fault: message['data']['error'] = fault.faultString - message['data']['log'] = self.processmanager.read_stderr(data['process_name']) - return message finally: + message['data']['stdout'] = self.processmanager.read_stdout(data['process_name']) + message['data']['stderr'] = self.processmanager.read_stderr(data['process_name']) self.processmanager.clear_logs(data['process_name']) + return message except KeyError: LOG.error('IGNORING MESSAGE: Invalid message received: %s', message) diff --git a/lib/tfw/mixins/supervisor_mixin.py b/lib/tfw/mixins/supervisor_mixin.py index 4586e85..f9bbd6b 100644 --- a/lib/tfw/mixins/supervisor_mixin.py +++ b/lib/tfw/mixins/supervisor_mixin.py @@ -35,5 +35,8 @@ class SupervisorLogMixin(SupervisorBaseMixin): def clear_logs(self, process_name): for logfile in ('stdout_logfile', 'stderr_logfile'): - remove(self.supervisor.getProcessInfo(process_name)[logfile]) + try: + remove(self.supervisor.getProcessInfo(process_name)[logfile]) + except FileNotFoundError: + pass self.supervisor.clearProcessLogs(process_name) From a6d9b50b937a401246a329ab01295885d6aa79cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Tue, 29 May 2018 10:12:59 +0200 Subject: [PATCH 04/14] Log everything from supervisor to stdout to avoid log recursion --- supervisor/supervisord.conf | 1 - 1 file changed, 1 deletion(-) diff --git a/supervisor/supervisord.conf b/supervisor/supervisord.conf index 6e9e04c..80d98f3 100644 --- a/supervisor/supervisord.conf +++ b/supervisor/supervisord.conf @@ -1,6 +1,5 @@ [supervisord] user=root -logfile = /tmp/supervisord.log loglevel = debug pidfile = /tmp/supervisord.pid From 029f4a9eb20e88095d43c578e171b44bc0bf1101 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Tue, 29 May 2018 10:26:15 +0200 Subject: [PATCH 05/14] Implement watchdog observer to watch the logs of a supervisor process --- lib/tfw/components/__init__.py | 1 + lib/tfw/components/log_monitor.py | 43 +++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 lib/tfw/components/log_monitor.py diff --git a/lib/tfw/components/__init__.py b/lib/tfw/components/__init__.py index f707c24..dee92a1 100644 --- a/lib/tfw/components/__init__.py +++ b/lib/tfw/components/__init__.py @@ -7,3 +7,4 @@ from .terminal_event_handler import TerminalEventHandler from .ide_event_handler import IdeEventHandler from .history_monitor import HistoryMonitor, BashMonitor, GDBMonitor from .terminal_commands import TerminalCommands +from .log_monitor import LogMonitor diff --git a/lib/tfw/components/log_monitor.py b/lib/tfw/components/log_monitor.py new file mode 100644 index 0000000..db66132 --- /dev/null +++ b/lib/tfw/components/log_monitor.py @@ -0,0 +1,43 @@ +# Copyright (C) 2018 Avatao.com Innovative Learning Kft. +# All Rights Reserved. See LICENSE file for details. + +from os.path import dirname + +from watchdog.events import PatternMatchingEventHandler as PatternMatchingWatchdogEventHandler + +from tfw.networking.event_handlers import ServerUplinkConnector +from tfw.decorators import RateLimiter +from tfw.mixins import ObserverMixin, SupervisorLogMixin + + +class LogMonitor(ObserverMixin): + def __init__(self, process_name): + ObserverMixin.__init__(self) + event_handler = SendLogWatchdogEventHandler(process_name) + self.observer.schedule( + event_handler, + event_handler.path + ) + + +class SendLogWatchdogEventHandler(PatternMatchingWatchdogEventHandler, SupervisorLogMixin): + def __init__(self, process_name): + self.process_name = process_name + self.procinfo = self.supervisor.getProcessInfo(self.process_name) + super().__init__([self.procinfo['stdout_logfile'], self.procinfo['stderr_logfile']]) + self.uplink = ServerUplinkConnector() + + @property + def path(self): + return dirname(self.procinfo['stdout_logfile']) + + @RateLimiter(rate_per_second=5) + def on_modified(self, event): + self.uplink.send({ + 'key': 'console', + 'data': { + 'command': 'writelog', + 'stdout': self.read_stdout(self.process_name), + 'stderr': self.read_stderr(self.process_name) + } + }) 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 06/14] 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): From 780d6a9b3c31bbe9e890b99f5dfb66fa5741aa09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Tue, 29 May 2018 11:05:45 +0200 Subject: [PATCH 07/14] =?UTF-8?q?Avoid=20pylint=20stupidity=20=C2=AF\=5F(?= =?UTF-8?q?=E3=83=84)=5F/=C2=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tfw/components/process_managing_event_handler.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tfw/components/process_managing_event_handler.py b/lib/tfw/components/process_managing_event_handler.py index 2044a38..3dba0d6 100644 --- a/lib/tfw/components/process_managing_event_handler.py +++ b/lib/tfw/components/process_managing_event_handler.py @@ -52,6 +52,6 @@ class ProcessManagingEventHandler(EventHandlerBase): message['data']['stdout'] = self.processmanager.read_stdout(data['process_name']) message['data']['stderr'] = self.processmanager.read_stderr(data['process_name']) self.processmanager.clear_logs(data['process_name']) - return message + return message except KeyError: LOG.error('IGNORING MESSAGE: Invalid message received: %s', message) From 9f6418bf60142a3d0cfc427cea8d59793793f9c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Tue, 29 May 2018 16:09:41 +0200 Subject: [PATCH 08/14] Support creating thread-local xmlrpc clients in SupervisorBaseMixin --- lib/tfw/mixins/supervisor_mixin.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/tfw/mixins/supervisor_mixin.py b/lib/tfw/mixins/supervisor_mixin.py index f9bbd6b..cbd6fcd 100644 --- a/lib/tfw/mixins/supervisor_mixin.py +++ b/lib/tfw/mixins/supervisor_mixin.py @@ -9,8 +9,18 @@ from os import remove from tfw.config import TFWENV +def get_supervisor_instance(): + return xmlrpc.client.ServerProxy(TFWENV.SUPERVISOR_HTTP_URI).supervisor + + class SupervisorBaseMixin: - supervisor = xmlrpc.client.ServerProxy(TFWENV.SUPERVISOR_HTTP_URI).supervisor + supervisor = get_supervisor_instance() + + def threadlocalise_supervisor_instance(self): + """ + Give this instance non-static, thread local xmlrpc client + """ + self.supervisor = get_supervisor_instance() class SupervisorMixin(SupervisorBaseMixin): From 4815b97200446c40241699e882f30a44c08e6790 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Tue, 29 May 2018 16:11:28 +0200 Subject: [PATCH 09/14] Fix shared xmlrpc client raising HTTP errors in LogMonitor --- lib/tfw/components/log_monitor.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/tfw/components/log_monitor.py b/lib/tfw/components/log_monitor.py index e3b5e2b..bebc172 100644 --- a/lib/tfw/components/log_monitor.py +++ b/lib/tfw/components/log_monitor.py @@ -29,6 +29,7 @@ class LogMonitor(ObserverMixin): class SendLogWatchdogEventHandler(PatternMatchingWatchdogEventHandler, SupervisorLogMixin): def __init__(self, process_name): + self.threadlocalise_supervisor_instance() self.process_name = process_name self.procinfo = self.supervisor.getProcessInfo(self.process_name) super().__init__([self.procinfo['stdout_logfile'], self.procinfo['stderr_logfile']]) @@ -41,9 +42,9 @@ class SendLogWatchdogEventHandler(PatternMatchingWatchdogEventHandler, Superviso @RateLimiter(rate_per_second=5) def on_modified(self, event): self.uplink.send({ - 'key': 'console', + 'key': 'processlog', 'data': { - 'command': 'writelog', + 'command': 'new_log', 'stdout': self.read_stdout(self.process_name), 'stderr': self.read_stderr(self.process_name) } From 28c16e112796b3bcd256410a9e8015d1bde083c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Tue, 29 May 2018 17:59:16 +0200 Subject: [PATCH 10/14] =?UTF-8?q?Rework=20log=20deletion=20=E2=80=93=20use?= =?UTF-8?q?=20log=5Ftail=20arguments=20instead?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tfw/components/log_monitor.py | 11 ++++++----- lib/tfw/components/process_managing_event_handler.py | 8 ++++---- lib/tfw/mixins/supervisor_mixin.py | 8 ++++---- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/lib/tfw/components/log_monitor.py b/lib/tfw/components/log_monitor.py index bebc172..af1d526 100644 --- a/lib/tfw/components/log_monitor.py +++ b/lib/tfw/components/log_monitor.py @@ -12,10 +12,10 @@ from tfw.mixins import ObserverMixin, SupervisorLogMixin class LogMonitor(ObserverMixin): - def __init__(self, process_name): + def __init__(self, process_name, log_tail=0): self.prevent_log_recursion() ObserverMixin.__init__(self) - event_handler = SendLogWatchdogEventHandler(process_name) + event_handler = SendLogWatchdogEventHandler(process_name, log_tail=log_tail) self.observer.schedule( event_handler, event_handler.path @@ -28,12 +28,13 @@ class LogMonitor(ObserverMixin): class SendLogWatchdogEventHandler(PatternMatchingWatchdogEventHandler, SupervisorLogMixin): - def __init__(self, process_name): + def __init__(self, process_name, log_tail=0): self.threadlocalise_supervisor_instance() self.process_name = process_name self.procinfo = self.supervisor.getProcessInfo(self.process_name) super().__init__([self.procinfo['stdout_logfile'], self.procinfo['stderr_logfile']]) self.uplink = ServerUplinkConnector() + self.log_tail = log_tail @property def path(self): @@ -45,7 +46,7 @@ class SendLogWatchdogEventHandler(PatternMatchingWatchdogEventHandler, Superviso 'key': 'processlog', 'data': { 'command': 'new_log', - 'stdout': self.read_stdout(self.process_name), - 'stderr': self.read_stderr(self.process_name) + 'stdout': self.read_stdout(self.process_name, tail=self.log_tail), + 'stderr': self.read_stderr(self.process_name, tail=self.log_tail) } }) diff --git a/lib/tfw/components/process_managing_event_handler.py b/lib/tfw/components/process_managing_event_handler.py index 3dba0d6..a512c1e 100644 --- a/lib/tfw/components/process_managing_event_handler.py +++ b/lib/tfw/components/process_managing_event_handler.py @@ -34,11 +34,12 @@ class ProcessManagingEventHandler(EventHandlerBase): Commands available: start, stop, restart, readlog (the names are as self-documenting as it gets) """ - def __init__(self, key, dirmonitor=None): + def __init__(self, key, dirmonitor=None, log_tail=0): super().__init__(key) self.key = key self.monitor = dirmonitor self.processmanager = ProcessManager() + self.log_tail = log_tail @with_monitor_paused def handle_event(self, message): @@ -49,9 +50,8 @@ class ProcessManagingEventHandler(EventHandlerBase): except SupervisorFault as fault: message['data']['error'] = fault.faultString finally: - message['data']['stdout'] = self.processmanager.read_stdout(data['process_name']) - message['data']['stderr'] = self.processmanager.read_stderr(data['process_name']) - self.processmanager.clear_logs(data['process_name']) + message['data']['stdout'] = self.processmanager.read_stdout(data['process_name'], self.log_tail) + message['data']['stderr'] = self.processmanager.read_stderr(data['process_name'], self.log_tail) return message except KeyError: LOG.error('IGNORING MESSAGE: Invalid message received: %s', message) diff --git a/lib/tfw/mixins/supervisor_mixin.py b/lib/tfw/mixins/supervisor_mixin.py index cbd6fcd..d005527 100644 --- a/lib/tfw/mixins/supervisor_mixin.py +++ b/lib/tfw/mixins/supervisor_mixin.py @@ -37,11 +37,11 @@ class SupervisorMixin(SupervisorBaseMixin): class SupervisorLogMixin(SupervisorBaseMixin): - def read_stdout(self, process_name): - return self.supervisor.readProcessStdoutLog(process_name, 0, 0) + def read_stdout(self, process_name, tail=0): + return self.supervisor.readProcessStdoutLog(process_name, -tail, 0) - def read_stderr(self, process_name): - return self.supervisor.readProcessStderrLog(process_name, 0, 0) + def read_stderr(self, process_name, tail=0): + return self.supervisor.readProcessStderrLog(process_name, -tail, 0) def clear_logs(self, process_name): for logfile in ('stdout_logfile', 'stderr_logfile'): From 9e6cd575321fceb66e5c9ba266e749da9f12c7d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Wed, 30 May 2018 13:06:09 +0200 Subject: [PATCH 11/14] Refactor MonitorManagerMixin to allow arbitrary Monitor arguments --- lib/tfw/mixins/monitor_manager_mixin.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/tfw/mixins/monitor_manager_mixin.py b/lib/tfw/mixins/monitor_manager_mixin.py index 16060ce..1f98314 100644 --- a/lib/tfw/mixins/monitor_manager_mixin.py +++ b/lib/tfw/mixins/monitor_manager_mixin.py @@ -7,10 +7,10 @@ LOG = logging.getLogger(__name__) class MonitorManagerMixin: - def __init__(self, monitor_type, directories): + def __init__(self, monitor_type, *monitor_args): self._monitor_type = monitor_type self._monitor = None - self._monitored_directories = directories + self._monitor_args = monitor_args self.reload_monitor() @property @@ -23,5 +23,5 @@ class MonitorManagerMixin: self._monitor.stop() except KeyError: LOG.debug('Working directory was removed – ignoring...') - self._monitor = self._monitor_type(self._monitored_directories) + self._monitor = self._monitor_type(*self._monitor_args) self._monitor.watch() # This runs on a separate thread From 3bb97a6dcccba52e7f54867e6fa8a2ebdc1dd669 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Wed, 30 May 2018 13:14:25 +0200 Subject: [PATCH 12/14] Implement LogMonitoringEventHandler to manage a LogMonitor via API --- lib/tfw/components/__init__.py | 2 +- .../components/log_monitoring_event_handler.py | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 lib/tfw/components/log_monitoring_event_handler.py diff --git a/lib/tfw/components/__init__.py b/lib/tfw/components/__init__.py index dee92a1..12735f9 100644 --- a/lib/tfw/components/__init__.py +++ b/lib/tfw/components/__init__.py @@ -7,4 +7,4 @@ from .terminal_event_handler import TerminalEventHandler from .ide_event_handler import IdeEventHandler from .history_monitor import HistoryMonitor, BashMonitor, GDBMonitor from .terminal_commands import TerminalCommands -from .log_monitor import LogMonitor +from .log_monitoring_event_handler import LogMonitoringEventHandler diff --git a/lib/tfw/components/log_monitoring_event_handler.py b/lib/tfw/components/log_monitoring_event_handler.py new file mode 100644 index 0000000..8d354a8 --- /dev/null +++ b/lib/tfw/components/log_monitoring_event_handler.py @@ -0,0 +1,15 @@ +# Copyright (C) 2018 Avatao.com Innovative Learning Kft. +# All Rights Reserved. See LICENSE file for details. + + +from tfw import EventHandlerBase +from tfw.mixins import MonitorManagerMixin +from .log_monitor import LogMonitor + + +class LogMonitoringEventHandler(EventHandlerBase, MonitorManagerMixin): + def __init__(self, process_name, log_tail=0): + MonitorManagerMixin.__init__(self, LogMonitor, process_name, log_tail) + + def handle_event(self, message): + pass From babb14288c901b68f553e38fc9d109a68556be8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Wed, 30 May 2018 14:03:59 +0200 Subject: [PATCH 13/14] Use contextlib.suppress() to suppress stuff in SupervisorLogMixin --- lib/tfw/mixins/supervisor_mixin.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/tfw/mixins/supervisor_mixin.py b/lib/tfw/mixins/supervisor_mixin.py index d005527..713f0da 100644 --- a/lib/tfw/mixins/supervisor_mixin.py +++ b/lib/tfw/mixins/supervisor_mixin.py @@ -45,8 +45,6 @@ class SupervisorLogMixin(SupervisorBaseMixin): def clear_logs(self, process_name): for logfile in ('stdout_logfile', 'stderr_logfile'): - try: + with suppress(FileNotFoundError): remove(self.supervisor.getProcessInfo(process_name)[logfile]) - except FileNotFoundError: - pass self.supervisor.clearProcessLogs(process_name) From 73f6c6635b7c79ab964e016c16631583100cfab6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Wed, 30 May 2018 14:07:40 +0200 Subject: [PATCH 14/14] Rename my bootiful threadlocalise.. SupervisorBaseMixin method --- lib/tfw/components/log_monitor.py | 2 +- lib/tfw/mixins/supervisor_mixin.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/tfw/components/log_monitor.py b/lib/tfw/components/log_monitor.py index af1d526..287618f 100644 --- a/lib/tfw/components/log_monitor.py +++ b/lib/tfw/components/log_monitor.py @@ -29,7 +29,7 @@ class LogMonitor(ObserverMixin): class SendLogWatchdogEventHandler(PatternMatchingWatchdogEventHandler, SupervisorLogMixin): def __init__(self, process_name, log_tail=0): - self.threadlocalise_supervisor_instance() + self.acquire_own_supervisor_instance() # This thread-localises the xmlrpc client self.process_name = process_name self.procinfo = self.supervisor.getProcessInfo(self.process_name) super().__init__([self.procinfo['stdout_logfile'], self.procinfo['stderr_logfile']]) diff --git a/lib/tfw/mixins/supervisor_mixin.py b/lib/tfw/mixins/supervisor_mixin.py index 713f0da..9360395 100644 --- a/lib/tfw/mixins/supervisor_mixin.py +++ b/lib/tfw/mixins/supervisor_mixin.py @@ -16,9 +16,9 @@ def get_supervisor_instance(): class SupervisorBaseMixin: supervisor = get_supervisor_instance() - def threadlocalise_supervisor_instance(self): + def acquire_own_supervisor_instance(self): """ - Give this instance non-static, thread local xmlrpc client + Give this instance non-static, local xmlrpc client """ self.supervisor = get_supervisor_instance()