From 1d47ca5684db5addde084ca0a5b54c4cda0bdcb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Tue, 13 Feb 2018 15:38:46 +0100 Subject: [PATCH] Add method EventHandlerBase.cleanup() --- lib/tfw/components/source_code_event_handler.py | 5 ++++- lib/tfw/event_handler_base.py | 3 +++ src/demo/event_handler_main.py | 9 ++++++--- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/tfw/components/source_code_event_handler.py b/lib/tfw/components/source_code_event_handler.py index eb22dce..5b5de40 100644 --- a/lib/tfw/components/source_code_event_handler.py +++ b/lib/tfw/components/source_code_event_handler.py @@ -58,7 +58,7 @@ class SourceCodeEventHandler(EventHandlerBase, SupervisorMixin): } self.monitor = DirectoryMonitor(directory) - self.monitor.watch() # This runs on a separate thread TODO: when to call stop()? + self.monitor.watch() # This runs on a separate thread def read(self, data): try: data['content'] = self.filemanager.file_contents @@ -89,6 +89,9 @@ class SourceCodeEventHandler(EventHandlerBase, SupervisorMixin): self.attach_fileinfo(data) return data_json + def cleanup(self): + self.monitor.stop() + def map_file_extension_to_language(filename): language_map = { diff --git a/lib/tfw/event_handler_base.py b/lib/tfw/event_handler_base.py index 4dfdb84..2841e0f 100644 --- a/lib/tfw/event_handler_base.py +++ b/lib/tfw/event_handler_base.py @@ -23,6 +23,9 @@ class EventHandlerBase: def handle_reset(self, data_json): return None + def cleanup(self): + pass + def message_other(self, anchor, data): message = { 'anchor': anchor, diff --git a/src/demo/event_handler_main.py b/src/demo/event_handler_main.py index f7623a9..dda5c36 100644 --- a/src/demo/event_handler_main.py +++ b/src/demo/event_handler_main.py @@ -6,6 +6,9 @@ from tfw.config import tfwenv if __name__ == '__main__': - anchor_webide = SourceCodeEventHandler('anchor_webide', tfwenv.WEBIDE_WD, 'login') - anchor_terminado = TerminadoEventHandler('anchor_terminado', 'terminado') - IOLoop.instance().start() + eventhandlers = {SourceCodeEventHandler('anchor_webide', tfwenv.WEBIDE_WD, 'login'), + TerminadoEventHandler('anchor_terminado', 'terminado')} + try: + IOLoop.instance().start() + finally: + for eh in eventhandlers: eh.cleanup()