try to send a response even if something happend

This commit is contained in:
Benoit Chesneau 2010-01-29 16:20:26 +01:00
parent 57054f1a4c
commit ddb48593f3
2 changed files with 19 additions and 2 deletions

View File

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

View File

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