From ddb48593f3d6734ba850426f13c1c7ca5870187f Mon Sep 17 00:00:00 2001 From: Benoit Chesneau Date: Fri, 29 Jan 2010 16:20:26 +0100 Subject: [PATCH] try to send a response even if something happend --- gunicorn/util.py | 12 +++++++++++- gunicorn/worker.py | 9 ++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/gunicorn/util.py b/gunicorn/util.py index 147b9a19..311c87be 100644 --- a/gunicorn/util.py +++ b/gunicorn/util.py @@ -60,7 +60,17 @@ def write(sock, data): break raise i += 1 - + +def write_nonblock(sock, data): + timeout = sock.gettimeout() + if timeout != "0.0": + sock.setblockin(0) + ret = write(sock, data) + sock.setblocking(1) + return ret + else: + return write(sock, data) + def writelines(sock, lines): for line in list(lines): write(sock, line) diff --git a/gunicorn/worker.py b/gunicorn/worker.py index 9ac365aa..873e6af8 100644 --- a/gunicorn/worker.py +++ b/gunicorn/worker.py @@ -133,7 +133,14 @@ class Worker(object): return http.HttpResponse(client, response, req).send() except Exception, e: - self.log.exception("Error processing request. [%s]" % str(e)) + self.log.exception("Error processing request. [%s]" % str(e)) + + # try to send a response even if something happend + try: + write_nonblock(sock, + "HTTP/1.0 500 Internal Server Error\r\n\r\n") + except: + pass finally: util.close(client)