This commit is contained in:
Benoit Chesneau 2010-02-03 12:01:45 +01:00
parent f3822a7f2f
commit 957496304c
3 changed files with 29 additions and 19 deletions

View File

@ -204,11 +204,12 @@ class Arbiter(object):
except StopIteration:
break
except KeyboardInterrupt:
self.stop(False)
sys.exit(-1)
break
except Exception:
self.log.info("Unhandled exception in main loop.")
self.stop(False)
if self.pidfile:
self.unlink_pidfile(self.pidfile)
sys.exit(-1)
self.stop()
@ -219,7 +220,6 @@ class Arbiter(object):
def handle_chld(self, sig, frame):
self.wakeup()
self.reap_workers()
def handle_hup(self):
self.log.info("Master hang up.")

View File

@ -170,7 +170,7 @@ def run():
main(__usage__, get_app)
def run_django():
from django.core.handlers.wsgi import WSGIHandler
import django.core.handlers.wsgi
PROJECT_PATH = os.getcwd()
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):
# django wsgi app
return WSGIHandler()
return django.core.handlers.wsgi.WSGIHandler()
main(__usage__, get_app)

View File

@ -22,7 +22,7 @@ class Worker(object):
SIGNALS = map(
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 = []
@ -35,22 +35,15 @@ class Worker(object):
self.debug = debug
self.socket = socket
self.timeout = timeout
fd, tmpname = tempfile.mkstemp()
self.tmp = os.fdopen(fd, "r+b")
self.fd, tmpname = tempfile.mkstemp()
self.tmp = os.fdopen(self.fd, "r+b")
self.tmpname = tmpname
self.app = app
self.alive = True
self.log = logging.getLogger(__name__)
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()
@ -87,9 +80,21 @@ class Worker(object):
os.fchmod(self.tmp.fileno(), self.spinner)
else:
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):
self.init_signals()
self.init_process()
self.nr = 0
# self.socket appears to lose its blocking status after
@ -106,11 +111,12 @@ class Worker(object):
except socket.error, e:
if e[0] not in (errno.EAGAIN, errno.ECONNABORTED):
raise
if self.nr < 0: break
# Keep processing clients until no one is waiting.
# This prevents the need to select() for every
# client that we process.
if self.nr > 0:
if self.nr != 0:
continue
# If our parent changed then we shut down.
@ -118,6 +124,7 @@ class Worker(object):
self.log.info("Parent process changed. Closing %s" % self)
return
self.notify()
try:
self.notify()
ret = select.select([self.socket], [], self.PIPE, self.timeout)
@ -126,8 +133,11 @@ class Worker(object):
except select.error, e:
if e[0] == errno.EINTR:
continue
if e[0] == errno.EBADF and self.nr < 0:
continue
if e[0] == errno.EBADF:
if self.nr < 0:
continue
else:
return
raise
def handle(self, client, addr):