from shutil import rmtree, copytree from xmlrpc.client import Fault as SupervisorFault from event_handler_base import EventHandlerBase from util import SupervisorMixin from config import TERMINADO_DIR class TerminadoEventHandler(EventHandlerBase, SupervisorMixin): def __init__(self, anchor, process_name, zmq_context=None): super().__init__(anchor, zmq_context) self.working_directory = TERMINADO_DIR self.process_name = process_name self.setup_terminado_server() def setup_terminado_server(self): rmtree(self.working_directory, ignore_errors=True) copytree('terminado_server/', self.working_directory) self.supervisor.startProcess(self.process_name) 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)