mirror of
https://github.com/frappe/gunicorn.git
synced 2026-01-14 11:09:11 +08:00
fix workers relaunch
This commit is contained in:
parent
9900371813
commit
ecd684eaed
@ -127,8 +127,9 @@ class Arbiter(object):
|
|||||||
return sock
|
return sock
|
||||||
|
|
||||||
def set_sockopts(self, sock):
|
def set_sockopts(self, sock):
|
||||||
|
|
||||||
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||||
sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
|
sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 0)
|
||||||
if hasattr(socket, "TCP_CORK"):
|
if hasattr(socket, "TCP_CORK"):
|
||||||
sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_CORK, 1)
|
sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_CORK, 1)
|
||||||
elif hasattr(socket, "TCP_NOPUSH"):
|
elif hasattr(socket, "TCP_NOPUSH"):
|
||||||
@ -140,6 +141,9 @@ class Arbiter(object):
|
|||||||
try:
|
try:
|
||||||
sig = self.SIG_QUEUE.pop(0) if len(self.SIG_QUEUE) else None
|
sig = self.SIG_QUEUE.pop(0) if len(self.SIG_QUEUE) else None
|
||||||
if sig is None:
|
if sig is None:
|
||||||
|
self.murder_workers()
|
||||||
|
self.reap_workers()
|
||||||
|
self.manage_workers()
|
||||||
self.sleep()
|
self.sleep()
|
||||||
continue
|
continue
|
||||||
|
|
||||||
@ -155,9 +159,6 @@ class Arbiter(object):
|
|||||||
log.info("Handling signal: %s" % signame)
|
log.info("Handling signal: %s" % signame)
|
||||||
handler()
|
handler()
|
||||||
|
|
||||||
self.murder_workers()
|
|
||||||
self.reap_workers()
|
|
||||||
self.manage_workers()
|
|
||||||
except StopIteration:
|
except StopIteration:
|
||||||
break
|
break
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
|
|||||||
@ -69,13 +69,11 @@ class HTTPRequest(object):
|
|||||||
remain = CHUNK_SIZE
|
remain = CHUNK_SIZE
|
||||||
buf = create_string_buffer(remain)
|
buf = create_string_buffer(remain)
|
||||||
remain -= self.socket.recv_into(buf, remain)
|
remain -= self.socket.recv_into(buf, remain)
|
||||||
|
|
||||||
while not self.parser.headers(headers, buf):
|
while not self.parser.headers(headers, buf):
|
||||||
data = create_string_buffer(remain)
|
data = create_string_buffer(remain)
|
||||||
remain -= self.socket.recv_into(data, remain)
|
remain -= self.socket.recv_into(data, remain)
|
||||||
buf = create_string_buffer(data.value + buf.value)
|
buf = create_string_buffer(data.value + buf.value)
|
||||||
|
|
||||||
print headers
|
|
||||||
if headers.get('Except', '').lower() == "100-continue":
|
if headers.get('Except', '').lower() == "100-continue":
|
||||||
self.socket.send("100 Continue\n")
|
self.socket.send("100 Continue\n")
|
||||||
|
|
||||||
|
|||||||
@ -53,11 +53,9 @@ class HTTPResponse(object):
|
|||||||
|
|
||||||
self.sock.send("%s\r\n" % "".join(resp_head))
|
self.sock.send("%s\r\n" % "".join(resp_head))
|
||||||
|
|
||||||
|
|
||||||
for chunk in self.data:
|
for chunk in self.data:
|
||||||
self.sock.send(chunk)
|
self.sock.send(chunk)
|
||||||
|
|
||||||
print "sent"
|
|
||||||
self.sock.close()
|
self.sock.close()
|
||||||
|
|
||||||
if hasattr(self.data, "close"):
|
if hasattr(self.data, "close"):
|
||||||
|
|||||||
@ -26,7 +26,7 @@
|
|||||||
|
|
||||||
import time
|
import time
|
||||||
|
|
||||||
CHUNK_SIZE = 16 * 1024
|
CHUNK_SIZE = (16 * 1024)
|
||||||
|
|
||||||
MAX_BODY = 1024 * (80 + 32)
|
MAX_BODY = 1024 * (80 + 32)
|
||||||
|
|
||||||
|
|||||||
@ -102,25 +102,20 @@ class Worker(object):
|
|||||||
except select.error, e:
|
except select.error, e:
|
||||||
if e[0] == errno.EINTR:
|
if e[0] == errno.EINTR:
|
||||||
break
|
break
|
||||||
elif e[0] == errno.EBADF:
|
|
||||||
return
|
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
|
||||||
# Accept until we hit EAGAIN. We're betting that when we're
|
# Accept until we hit EAGAIN. We're betting that when we're
|
||||||
# processing clients that more clients are waiting. When
|
# processing clients that more clients are waiting. When
|
||||||
# there's no more clients waiting we go back to the select()
|
# there's no more clients waiting we go back to the select()
|
||||||
# loop and wait for some lovin.
|
# loop and wait for some lovin.
|
||||||
while self.alive:
|
while self.alive:
|
||||||
try:
|
try:
|
||||||
|
|
||||||
conn, addr = self.socket.accept()
|
conn, addr = self.socket.accept()
|
||||||
conn.setblocking(1)
|
conn.setblocking(1)
|
||||||
|
|
||||||
# handle connection
|
# handle connection
|
||||||
self.handle(conn, addr)
|
self.handle(conn, addr)
|
||||||
|
|
||||||
|
|
||||||
# Update the fd mtime on each client completion
|
# Update the fd mtime on each client completion
|
||||||
# to signal that this worker process is alive.
|
# to signal that this worker process is alive.
|
||||||
spinner = (spinner+1) % 2
|
spinner = (spinner+1) % 2
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user