mirror of
https://github.com/frappe/gunicorn.git
synced 2026-01-14 11:09:11 +08:00
Merge branch 'master' of github.com:benoitc/gunicorn
This commit is contained in:
commit
b4d4427416
@ -22,9 +22,4 @@ class WSGIApplication(Application):
|
|||||||
sys.path.insert(0, os.getcwd())
|
sys.path.insert(0, os.getcwd())
|
||||||
|
|
||||||
def load(self):
|
def load(self):
|
||||||
try:
|
return util.import_app(self.app_uri)
|
||||||
return util.import_app(self.app_uri)
|
|
||||||
except:
|
|
||||||
print "Failed to import application: %s" % self.app_uri
|
|
||||||
traceback.print_exc()
|
|
||||||
sys.exit(1)
|
|
||||||
|
|||||||
@ -24,7 +24,12 @@ class Arbiter(object):
|
|||||||
kills them if needed. It also manages application reloading
|
kills them if needed. It also manages application reloading
|
||||||
via SIGHUP/USR2.
|
via SIGHUP/USR2.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# A flag indicating if a worker failed to
|
||||||
|
# to boot. If a worker process exist with
|
||||||
|
# this error code, the arbiter will terminate.
|
||||||
|
WORKER_BOOT_ERROR = 3
|
||||||
|
|
||||||
START_CTX = {}
|
START_CTX = {}
|
||||||
|
|
||||||
LISTENER = None
|
LISTENER = None
|
||||||
@ -322,10 +327,16 @@ class Arbiter(object):
|
|||||||
try:
|
try:
|
||||||
while True:
|
while True:
|
||||||
wpid, status = os.waitpid(-1, os.WNOHANG)
|
wpid, status = os.waitpid(-1, os.WNOHANG)
|
||||||
if not wpid: break
|
if not wpid:
|
||||||
|
break
|
||||||
if self.reexec_pid == wpid:
|
if self.reexec_pid == wpid:
|
||||||
self.reexec_pid = 0
|
self.reexec_pid = 0
|
||||||
else:
|
else:
|
||||||
|
# A worker said it cannot boot. We'll shutdown
|
||||||
|
# to avoid infinite start/stop cycles.
|
||||||
|
exitcode = status >> 8
|
||||||
|
if exitcode == self.WORKER_BOOT_ERROR:
|
||||||
|
raise StopIteration
|
||||||
worker = self.WORKERS.pop(wpid, None)
|
worker = self.WORKERS.pop(wpid, None)
|
||||||
if not worker:
|
if not worker:
|
||||||
continue
|
continue
|
||||||
@ -380,7 +391,9 @@ class Arbiter(object):
|
|||||||
except SystemExit:
|
except SystemExit:
|
||||||
raise
|
raise
|
||||||
except:
|
except:
|
||||||
self.log.exception("Exception in worker process.")
|
self.log.exception("Exception in worker process:")
|
||||||
|
if not worker.booted:
|
||||||
|
sys.exit(self.WORKER_BOOT_ERROR)
|
||||||
sys.exit(-1)
|
sys.exit(-1)
|
||||||
finally:
|
finally:
|
||||||
self.log.info("Worker exiting (pid: %s)" % worker_pid)
|
self.log.info("Worker exiting (pid: %s)" % worker_pid)
|
||||||
|
|||||||
@ -33,7 +33,8 @@ class Worker(object):
|
|||||||
self.app = app
|
self.app = app
|
||||||
self.timeout = timeout
|
self.timeout = timeout
|
||||||
self.cfg = cfg
|
self.cfg = cfg
|
||||||
|
self.booted = False
|
||||||
|
|
||||||
self.nr = 0
|
self.nr = 0
|
||||||
self.alive = True
|
self.alive = True
|
||||||
self.spinner = 0
|
self.spinner = 0
|
||||||
@ -94,6 +95,7 @@ class Worker(object):
|
|||||||
self.wsgi = self.app.wsgi()
|
self.wsgi = self.app.wsgi()
|
||||||
|
|
||||||
# Enter main run loop
|
# Enter main run loop
|
||||||
|
self.booted = True
|
||||||
self.run()
|
self.run()
|
||||||
|
|
||||||
def init_signals(self):
|
def init_signals(self):
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user