From c7bc588397d7d8afaf2b1ef3fa1d24f6dd568302 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Wed, 24 Jan 2018 15:54:03 +0100 Subject: [PATCH] Refactor for handling xmlrpc exceptiions --- src/event_handlers/source_code_event_handler.py | 9 +++++---- src/event_handlers/terminado_event_handler.py | 6 ++++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/event_handlers/source_code_event_handler.py b/src/event_handlers/source_code_event_handler.py index 8fc5569..703da75 100644 --- a/src/event_handlers/source_code_event_handler.py +++ b/src/event_handlers/source_code_event_handler.py @@ -1,5 +1,6 @@ from shutil import copy, rmtree, copytree from os.path import splitext +from xmlrpc.client import Fault as SupervisorFault from util import SupervisorMixin from config import LOGIN_APP_DIR @@ -26,7 +27,7 @@ class SourceCodeEventHandler(EventHandlerBase, SupervisorMixin): return data_json def handle_reset(self, data_json): - self.create_initial_state(process_is_running=True) + self.create_initial_state() def read_file(self, data_json): with open(self.file, 'r') as ifile: @@ -44,9 +45,9 @@ class SourceCodeEventHandler(EventHandlerBase, SupervisorMixin): self.supervisor.stopProcess(self.process_name) self.supervisor.startProcess(self.process_name) - def create_initial_state(self, process_is_running=False): - if process_is_running: - self.supervisor.stopProcess(self.process_name) + def create_initial_state(self): + try: self.supervisor.stopProcess(self.process_name) + except SupervisorFault: pass rmtree(self.working_directory, ignore_errors=True) copytree('source_code_server/', self.working_directory) diff --git a/src/event_handlers/terminado_event_handler.py b/src/event_handlers/terminado_event_handler.py index fc12471..4c69809 100644 --- a/src/event_handlers/terminado_event_handler.py +++ b/src/event_handlers/terminado_event_handler.py @@ -1,4 +1,5 @@ from shutil import rmtree, copytree +from xmlrpc.client import Fault as SupervisorFault from event_handler_base import EventHandlerBase from util import SupervisorMixin @@ -19,3 +20,8 @@ class TerminadoEventHandler(EventHandlerBase, SupervisorMixin): def handle_event(self, anchor, data_json): raise NotImplementedError # TODO: wat do? + + def handle_reset(self, data_json): + try: self.supervisor.stopProcess(self.process_name) + except SupervisorFault: pass + self.supervisor.startProcess(self.process_name)