mirror of
https://github.com/frappe/gunicorn.git
synced 2026-01-14 11:09:11 +08:00
fix #8.
This commit is contained in:
parent
f3822a7f2f
commit
957496304c
@ -204,11 +204,12 @@ class Arbiter(object):
|
|||||||
except StopIteration:
|
except StopIteration:
|
||||||
break
|
break
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
self.stop(False)
|
break
|
||||||
sys.exit(-1)
|
|
||||||
except Exception:
|
except Exception:
|
||||||
self.log.info("Unhandled exception in main loop.")
|
self.log.info("Unhandled exception in main loop.")
|
||||||
self.stop(False)
|
self.stop(False)
|
||||||
|
if self.pidfile:
|
||||||
|
self.unlink_pidfile(self.pidfile)
|
||||||
sys.exit(-1)
|
sys.exit(-1)
|
||||||
|
|
||||||
self.stop()
|
self.stop()
|
||||||
@ -219,7 +220,6 @@ class Arbiter(object):
|
|||||||
|
|
||||||
def handle_chld(self, sig, frame):
|
def handle_chld(self, sig, frame):
|
||||||
self.wakeup()
|
self.wakeup()
|
||||||
self.reap_workers()
|
|
||||||
|
|
||||||
def handle_hup(self):
|
def handle_hup(self):
|
||||||
self.log.info("Master hang up.")
|
self.log.info("Master hang up.")
|
||||||
|
|||||||
@ -170,7 +170,7 @@ def run():
|
|||||||
main(__usage__, get_app)
|
main(__usage__, get_app)
|
||||||
|
|
||||||
def run_django():
|
def run_django():
|
||||||
from django.core.handlers.wsgi import WSGIHandler
|
import django.core.handlers.wsgi
|
||||||
|
|
||||||
PROJECT_PATH = os.getcwd()
|
PROJECT_PATH = os.getcwd()
|
||||||
if not os.path.isfile(os.path.join(PROJECT_PATH, "settings.py")):
|
if not os.path.isfile(os.path.join(PROJECT_PATH, "settings.py")):
|
||||||
@ -188,7 +188,7 @@ def run_django():
|
|||||||
|
|
||||||
def get_app(parser, opts, args):
|
def get_app(parser, opts, args):
|
||||||
# django wsgi app
|
# django wsgi app
|
||||||
return WSGIHandler()
|
return django.core.handlers.wsgi.WSGIHandler()
|
||||||
|
|
||||||
main(__usage__, get_app)
|
main(__usage__, get_app)
|
||||||
|
|
||||||
|
|||||||
@ -22,7 +22,7 @@ class Worker(object):
|
|||||||
|
|
||||||
SIGNALS = map(
|
SIGNALS = map(
|
||||||
lambda x: getattr(signal, "SIG%s" % x),
|
lambda x: getattr(signal, "SIG%s" % x),
|
||||||
"HUP QUIT INT TERM TTIN TTOU USR1 USR2 WINCH".split()
|
"CHLD HUP QUIT INT TERM TTIN TTOU USR1 USR2 WINCH".split()
|
||||||
)
|
)
|
||||||
|
|
||||||
PIPE = []
|
PIPE = []
|
||||||
@ -35,22 +35,15 @@ class Worker(object):
|
|||||||
self.debug = debug
|
self.debug = debug
|
||||||
self.socket = socket
|
self.socket = socket
|
||||||
self.timeout = timeout
|
self.timeout = timeout
|
||||||
fd, tmpname = tempfile.mkstemp()
|
self.fd, tmpname = tempfile.mkstemp()
|
||||||
self.tmp = os.fdopen(fd, "r+b")
|
self.tmp = os.fdopen(self.fd, "r+b")
|
||||||
self.tmpname = tmpname
|
self.tmpname = tmpname
|
||||||
self.app = app
|
self.app = app
|
||||||
self.alive = True
|
self.alive = True
|
||||||
self.log = logging.getLogger(__name__)
|
self.log = logging.getLogger(__name__)
|
||||||
self.spinner = 0
|
self.spinner = 0
|
||||||
|
|
||||||
# init pipe
|
|
||||||
self.PIPE = os.pipe()
|
|
||||||
map(util.set_non_blocking, self.PIPE)
|
|
||||||
map(util.close_on_exec, self.PIPE)
|
|
||||||
|
|
||||||
# prevent inherientence
|
|
||||||
util.close_on_exec(self.socket)
|
|
||||||
util.close_on_exec(fd)
|
|
||||||
|
|
||||||
self.address = self.socket.getsockname()
|
self.address = self.socket.getsockname()
|
||||||
|
|
||||||
@ -87,9 +80,21 @@ class Worker(object):
|
|||||||
os.fchmod(self.tmp.fileno(), self.spinner)
|
os.fchmod(self.tmp.fileno(), self.spinner)
|
||||||
else:
|
else:
|
||||||
os.chmod(self.tmpname, self.spinner)
|
os.chmod(self.tmpname, self.spinner)
|
||||||
|
|
||||||
|
def init_process(self):
|
||||||
|
# init pipe
|
||||||
|
self.PIPE = os.pipe()
|
||||||
|
map(util.set_non_blocking, self.PIPE)
|
||||||
|
map(util.close_on_exec, self.PIPE)
|
||||||
|
|
||||||
|
# prevent inherientence
|
||||||
|
util.close_on_exec(self.socket)
|
||||||
|
util.close_on_exec(self.fd)
|
||||||
|
self.init_signals()
|
||||||
|
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
self.init_signals()
|
self.init_process()
|
||||||
self.nr = 0
|
self.nr = 0
|
||||||
|
|
||||||
# self.socket appears to lose its blocking status after
|
# self.socket appears to lose its blocking status after
|
||||||
@ -106,11 +111,12 @@ class Worker(object):
|
|||||||
except socket.error, e:
|
except socket.error, e:
|
||||||
if e[0] not in (errno.EAGAIN, errno.ECONNABORTED):
|
if e[0] not in (errno.EAGAIN, errno.ECONNABORTED):
|
||||||
raise
|
raise
|
||||||
|
if self.nr < 0: break
|
||||||
|
|
||||||
# Keep processing clients until no one is waiting.
|
# Keep processing clients until no one is waiting.
|
||||||
# This prevents the need to select() for every
|
# This prevents the need to select() for every
|
||||||
# client that we process.
|
# client that we process.
|
||||||
if self.nr > 0:
|
if self.nr != 0:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# If our parent changed then we shut down.
|
# If our parent changed then we shut down.
|
||||||
@ -118,6 +124,7 @@ class Worker(object):
|
|||||||
self.log.info("Parent process changed. Closing %s" % self)
|
self.log.info("Parent process changed. Closing %s" % self)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
self.notify()
|
||||||
try:
|
try:
|
||||||
self.notify()
|
self.notify()
|
||||||
ret = select.select([self.socket], [], self.PIPE, self.timeout)
|
ret = select.select([self.socket], [], self.PIPE, self.timeout)
|
||||||
@ -126,8 +133,11 @@ class Worker(object):
|
|||||||
except select.error, e:
|
except select.error, e:
|
||||||
if e[0] == errno.EINTR:
|
if e[0] == errno.EINTR:
|
||||||
continue
|
continue
|
||||||
if e[0] == errno.EBADF and self.nr < 0:
|
if e[0] == errno.EBADF:
|
||||||
continue
|
if self.nr < 0:
|
||||||
|
continue
|
||||||
|
else:
|
||||||
|
return
|
||||||
raise
|
raise
|
||||||
|
|
||||||
def handle(self, client, addr):
|
def handle(self, client, addr):
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user