mirror of
https://github.com/frappe/gunicorn.git
synced 2026-01-14 11:09:11 +08:00
add the graceful timeout option. close #352
This change add gtraceful timeout option. This timeout is different than the worker timeout and can be extended to handled a longer delay before closing a running connection. Patch based on the one given by @sirkonst with some edit + support of the eventlet worker.
This commit is contained in:
parent
a42daa03ed
commit
188fa3e109
@ -320,7 +320,7 @@ class Arbiter(object):
|
||||
sig = signal.SIGQUIT
|
||||
if not graceful:
|
||||
sig = signal.SIGTERM
|
||||
limit = time.time() + self.timeout
|
||||
limit = time.time() + self.cfg.graceful_timeout
|
||||
while self.WORKERS and time.time() < limit:
|
||||
self.kill_workers(sig)
|
||||
time.sleep(0.1)
|
||||
|
||||
@ -418,6 +418,22 @@ class Timeout(Setting):
|
||||
is not tied to the length of time required to handle a single request.
|
||||
"""
|
||||
|
||||
class GracefulTimeout(Setting):
|
||||
name = "graceful_timeout"
|
||||
section = "Worker Processes"
|
||||
cli = ["--graceful-timeout"]
|
||||
meta = "INT"
|
||||
validator = validate_pos_int
|
||||
type = "int"
|
||||
default = 30
|
||||
desc = """\
|
||||
Timeout for graceful workers restart.
|
||||
|
||||
Generally set to thirty seconds. How max time worker can handle
|
||||
request after got restart signal. If the time is up worker will
|
||||
be force killed.
|
||||
"""
|
||||
|
||||
class Keepalive(Setting):
|
||||
name = "keepalive"
|
||||
section = "Worker Processes"
|
||||
|
||||
@ -47,5 +47,5 @@ class EventletWorker(AsyncWorker):
|
||||
eventlet.sleep(1.0)
|
||||
|
||||
self.notify()
|
||||
with eventlet.Timeout(self.timeout, False):
|
||||
with eventlet.Timeout(self.cfg.graceful_timeout, False):
|
||||
eventlet.kill(self.acceptor, eventlet.StopServe)
|
||||
|
||||
@ -77,7 +77,7 @@ class GeventWorker(AsyncWorker):
|
||||
try:
|
||||
# Try to stop connections until timeout
|
||||
self.notify()
|
||||
server.stop(timeout=self.timeout)
|
||||
server.stop(timeout=self.cfg.graceful_timeout)
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user