Fix USR1 handling in workers.

This commit is contained in:
Paul J. Davis 2010-01-31 18:21:47 -05:00
parent 9dde33c15c
commit 84d4510847
2 changed files with 10 additions and 11 deletions

View File

@ -338,7 +338,7 @@ class Arbiter(object):
continue continue
worker = Worker(i, self.pid, self.LISTENER, self.modname, worker = Worker(i, self.pid, self.LISTENER, self.modname,
self.timeout/2, self.PIPE, self.debug) self.timeout/2, self.debug)
pid = os.fork() pid = os.fork()
if pid != 0: if pid != 0:
self.WORKERS[pid] = worker self.WORKERS[pid] = worker

View File

@ -27,8 +27,7 @@ class Worker(object):
PIPE = [] PIPE = []
def __init__(self, workerid, ppid, socket, app, def __init__(self, workerid, ppid, socket, app, timeout, debug=False):
timeout, pipe, debug=False):
self.nr = 0 self.nr = 0
self.id = workerid self.id = workerid
self.ppid = ppid self.ppid = ppid
@ -44,9 +43,9 @@ class Worker(object):
self.spinner = 0 self.spinner = 0
# init pipe # init pipe
self.PIPE = pipe self.PIPE = os.pipe()
map(util.set_non_blocking, pipe) map(util.set_non_blocking, self.PIPE)
map(util.close_on_exec, pipe) map(util.close_on_exec, self.PIPE)
# prevent inherientence # prevent inherientence
util.close_on_exec(self.socket) util.close_on_exec(self.socket)
@ -65,7 +64,8 @@ class Worker(object):
signal.signal(signal.SIGINT, self.handle_exit) signal.signal(signal.SIGINT, self.handle_exit)
def handle_usr1(self, sig, frame): def handle_usr1(self, sig, frame):
self.nr = -65536; self.log.info("USR1")
self.nr = -65536;
try: try:
map(lambda p: p.close(), self.PIPE) map(lambda p: p.close(), self.PIPE)
except: except:
@ -106,10 +106,9 @@ class Worker(object):
if e[0] not in (errno.EAGAIN, errno.ECONNABORTED): if e[0] not in (errno.EAGAIN, errno.ECONNABORTED):
raise raise
# Accept until we hit EAGAIN. We're betting that when we're # Keep processing clients until no one is waiting.
# processing clients that more clients are waiting. When # This prevents the need to select() for every
# there's no more clients waiting we go back to the select() # client that we process.
# loop and wait for some lovin.
if self.nr > 0: if self.nr > 0:
continue continue