From dab22737c73ba7adb7e7af5feda9de8636c9f372 Mon Sep 17 00:00:00 2001 From: AleaJactaEst Date: Sun, 7 Apr 2019 11:33:54 +0200 Subject: [PATCH] #88 - ignore BrokenPipeError --- pymanager/manager.py | 44 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 37 insertions(+), 7 deletions(-) diff --git a/pymanager/manager.py b/pymanager/manager.py index 98fda5f..bde5473 100755 --- a/pymanager/manager.py +++ b/pymanager/manager.py @@ -275,8 +275,13 @@ class ManageHttpRequest(http.server.SimpleHTTPRequestHandler): return self.server.listSemaphore[name].release() self._set_headers() - self.wfile.write(bytes(json.dumps(item), "utf-8")) - logging.debug("item : %s" % item) + try: + self.wfile.write(bytes(json.dumps(item), "utf-8")) + logging.debug("item : %s" % item) + except BrokenPipeError: + # ignore BrokenPipeError: [Errno 32] Broken pipe + logging.debug("BrokenPipeError detected") + pass def _send_list(self): """ sub-request to list all program available """ @@ -286,7 +291,12 @@ class ManageHttpRequest(http.server.SimpleHTTPRequestHandler): outjson.setdefault(pos, program) pos += 1 self._set_headers() - self.wfile.write(bytes(json.dumps(outjson), "utf-8")) + try: + self.wfile.write(bytes(json.dumps(outjson), "utf-8")) + except BrokenPipeError: + # ignore BrokenPipeError: [Errno 32] Broken pipe + logging.debug("BrokenPipeError detected") + pass def _send_shutdown(self): """ Stop all program and stop manager """ @@ -296,7 +306,12 @@ class ManageHttpRequest(http.server.SimpleHTTPRequestHandler): self.server.listSemaphore[name].release() self._set_headers() outjson = {'shutdown': 'ok'} - self.wfile.write(bytes(json.dumps(outjson), "utf-8")) + try: + self.wfile.write(bytes(json.dumps(outjson), "utf-8")) + except BrokenPipeError: + # ignore BrokenPipeError: [Errno 32] Broken pipe + logging.debug("BrokenPipeError detected") + pass def _send_command_all(self, command): """ Send specific command on all program @@ -315,7 +330,12 @@ class ManageHttpRequest(http.server.SimpleHTTPRequestHandler): self.server.listSemaphore[name].release() outjson.setdefault(name, item) self._set_headers() - self.wfile.write(bytes(json.dumps(outjson), "utf-8")) + try: + self.wfile.write(bytes(json.dumps(outjson), "utf-8")) + except BrokenPipeError: + # ignore BrokenPipeError: [Errno 32] Broken pipe + logging.debug("BrokenPipeError detected") + pass def _send_action(self): """ send specific action on one program """ @@ -359,7 +379,12 @@ class ManageHttpRequest(http.server.SimpleHTTPRequestHandler): return self.server.listSemaphore[name].release() self._set_headers() - self.wfile.write(bytes(json.dumps(outjson), "utf-8")) + try: + self.wfile.write(bytes(json.dumps(outjson), "utf-8")) + except BrokenPipeError: + # ignore BrokenPipeError: [Errno 32] Broken pipe + logging.debug("BrokenPipeError detected") + pass def _send_command(self, command): """ Send specific command on one program @@ -398,7 +423,12 @@ class ManageHttpRequest(http.server.SimpleHTTPRequestHandler): self.server.listSemaphore[name].release() logging.debug("[%s %s] => %s" % (command, name, outjson)) self._set_headers() - self.wfile.write(bytes(json.dumps(outjson), "utf-8")) + try: + self.wfile.write(bytes(json.dumps(outjson), "utf-8")) + except BrokenPipeError: + # ignore BrokenPipeError: [Errno 32] Broken pipe + logging.debug("BrokenPipeError detected") + pass def check_authentication(self): if not self.server.authentification: