Handling of xmlrpc exceptions is now done with contextlib.suppress()

This commit is contained in:
Kristóf Tóth 2018-01-24 18:28:45 +01:00
parent ae4c27c0f5
commit d7919255ec
2 changed files with 6 additions and 4 deletions

View File

@ -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)

View File

@ -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)