mirror of
https://github.com/frappe/gunicorn.git
synced 2026-01-14 11:09:11 +08:00
[ggevent] Stop quickly and cleanly on ppid change
This change should improve interaction with reloaders and ensure that ports are not stuck open if the arbiter gets a hard kill signal or otherwise exits during any graceful or non-graceful shutdown.
This commit is contained in:
parent
5afb03e6f4
commit
33f7c96db6
@ -50,6 +50,12 @@ class GeventWorker(AsyncWorker):
|
||||
monkey.noisy = False
|
||||
monkey.patch_all()
|
||||
|
||||
def notify(self):
|
||||
super(GeventWorker, self).notify()
|
||||
if self.ppid != os.getppid():
|
||||
self.log.info("Parent changed, shutting down: %s", self)
|
||||
sys.exit(0)
|
||||
|
||||
def timeout_ctx(self):
|
||||
return gevent.Timeout(self.cfg.keepalive, False)
|
||||
|
||||
@ -75,19 +81,19 @@ class GeventWorker(AsyncWorker):
|
||||
server.start()
|
||||
servers.append(server)
|
||||
|
||||
pid = os.getpid()
|
||||
try:
|
||||
while self.alive:
|
||||
self.notify()
|
||||
|
||||
if pid == os.getpid() and self.ppid != os.getppid():
|
||||
self.log.info("Parent changed, shutting down: %s", self)
|
||||
break
|
||||
|
||||
gevent.sleep(1.0)
|
||||
|
||||
except KeyboardInterrupt:
|
||||
pass
|
||||
except:
|
||||
try:
|
||||
server.stop()
|
||||
except:
|
||||
pass
|
||||
raise
|
||||
|
||||
try:
|
||||
# Stop accepting requests
|
||||
@ -119,6 +125,8 @@ class GeventWorker(AsyncWorker):
|
||||
super(GeventWorker, self).handle_request(*args)
|
||||
except gevent.GreenletExit:
|
||||
pass
|
||||
except SystemExit:
|
||||
pass
|
||||
|
||||
if gevent.version_info[0] == 0:
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user