#88 - ignore BrokenPipeError

This commit is contained in:
AleaJactaEst 2019-04-07 11:33:54 +02:00
parent 27e0b30541
commit dab22737c7

View file

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