mirror of
https://github.com/frappe/gunicorn.git
synced 2026-01-14 11:09:11 +08:00
we don't want to block accepted socket. Fix a bug I got with
friendpaste. also make worker select timeout related to arbiter.
This commit is contained in:
parent
43b9209144
commit
46086720f5
@ -267,7 +267,8 @@ class Arbiter(object):
|
||||
if i in workers:
|
||||
continue
|
||||
|
||||
worker = Worker(i, self.pid, self.LISTENER, self.modname)
|
||||
worker = Worker(i, self.pid, self.LISTENER, self.modname,
|
||||
self.timeout / 2.0)
|
||||
pid = os.fork()
|
||||
if pid != 0:
|
||||
self.WORKERS[pid] = worker
|
||||
|
||||
@ -24,14 +24,14 @@ class HTTPResponse(object):
|
||||
def send(self):
|
||||
# send headers
|
||||
resp_head = []
|
||||
resp_head.append("HTTP/1.0 %s\r\n" % (self.status))
|
||||
resp_head.append("HTTP/1.1 %s\r\n" % (self.status))
|
||||
|
||||
resp_head.append("Server: %s\r\n" % self.SERVER_VERSION)
|
||||
resp_head.append("Date: %s\r\n" % http_date())
|
||||
# broken clients
|
||||
resp_head.append("Status: %s\r\n" % str(self.status))
|
||||
# always close the conenction
|
||||
#resp_head.append("Connection: close\r\n")
|
||||
resp_head.append("Connection: close\r\n")
|
||||
for name, value in self.headers.items():
|
||||
resp_head.append("%s: %s\r\n" % (name, value))
|
||||
|
||||
|
||||
@ -60,7 +60,7 @@ def write(sock, data):
|
||||
if e[0] in (errno.EWOULDBLOCK, errno.EAGAIN):
|
||||
break
|
||||
elif e[0] in (errno.EPIPE,):
|
||||
break
|
||||
continue
|
||||
raise
|
||||
|
||||
def write_nonblock(sock, data):
|
||||
|
||||
@ -25,9 +25,10 @@ class Worker(object):
|
||||
"HUP QUIT INT TERM TTIN TTOU USR1".split()
|
||||
)
|
||||
|
||||
def __init__(self, workerid, ppid, socket, app):
|
||||
def __init__(self, workerid, ppid, socket, app, timeout):
|
||||
self.id = workerid
|
||||
self.ppid = ppid
|
||||
self.timeout = timeout
|
||||
fd, tmpname = tempfile.mkstemp()
|
||||
self.tmp = os.fdopen(fd, "r+b")
|
||||
self.tmpname = tmpname
|
||||
@ -76,7 +77,8 @@ class Worker(object):
|
||||
spinner = (spinner+1) % 2
|
||||
self._fchmod(spinner)
|
||||
try:
|
||||
ret = select.select([self.socket], [], [], 2.0)
|
||||
ret = select.select([self.socket], [], [],
|
||||
self.timeout)
|
||||
if ret[0]:
|
||||
break
|
||||
except select.error, e:
|
||||
@ -96,7 +98,8 @@ class Worker(object):
|
||||
while self.alive:
|
||||
try:
|
||||
client, addr = self.socket.accept()
|
||||
|
||||
client.setblocking(0)
|
||||
|
||||
# handle connection
|
||||
self.handle(client, addr)
|
||||
|
||||
@ -105,7 +108,8 @@ class Worker(object):
|
||||
spinner = (spinner+1) % 2
|
||||
self._fchmod(spinner)
|
||||
except socket.error, e:
|
||||
if e[0] in [errno.EAGAIN, errno.ECONNABORTED]:
|
||||
if e[0] in [errno.EAGAIN, errno.ECONNABORTED,
|
||||
errno.EWOULDBLOCK]:
|
||||
break # Uh oh!
|
||||
raise
|
||||
|
||||
@ -118,6 +122,6 @@ class Worker(object):
|
||||
except Exception, e:
|
||||
self.log.exception("Error processing request. [%s]" % str(e))
|
||||
# try to send something if an error happend
|
||||
msg = "HTTP/1.0 500 Internal Server Error\r\n\r\n"
|
||||
msg = "HTTP/1.1 500 Internal Server Error\r\n\r\n"
|
||||
util.write_nonblock(client, msg)
|
||||
util.close(client)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user