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)