From d7919255eccd0365d0a526fb8467c442f9fab9d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Wed, 24 Jan 2018 18:28:45 +0100 Subject: [PATCH] Handling of xmlrpc exceptions is now done with contextlib.suppress() --- src/event_handlers/source_code_event_handler.py | 5 +++-- src/event_handlers/terminado_event_handler.py | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/event_handlers/source_code_event_handler.py b/src/event_handlers/source_code_event_handler.py index 703da75..a2b99d7 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 contextlib import suppress from xmlrpc.client import Fault as SupervisorFault from util import SupervisorMixin @@ -46,8 +47,8 @@ class SourceCodeEventHandler(EventHandlerBase, SupervisorMixin): self.supervisor.startProcess(self.process_name) def create_initial_state(self): - try: self.supervisor.stopProcess(self.process_name) - except SupervisorFault: pass + with suppress(SupervisorFault): + self.supervisor.stopProcess(self.process_name) 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 00ffbae..966cb88 100644 --- a/src/event_handlers/terminado_event_handler.py +++ b/src/event_handlers/terminado_event_handler.py @@ -1,6 +1,7 @@ import logging from shutil import rmtree, copytree from xmlrpc.client import Fault as SupervisorFault +from contextlib import suppress from event_handler_base import EventHandlerBase from util import SupervisorMixin @@ -24,6 +25,6 @@ class TerminadoEventHandler(EventHandlerBase, SupervisorMixin): # TODO: wat do? def handle_reset(self, data_json): - try: self.supervisor.stopProcess(self.process_name) - except SupervisorFault: pass + with suppress(SupervisorFault): + self.supervisor.stopProcess(self.process_name) self.supervisor.startProcess(self.process_name)