diff --git a/gunicorn/arbiter.py b/gunicorn/arbiter.py index a2b0d029..2ac04e66 100644 --- a/gunicorn/arbiter.py +++ b/gunicorn/arbiter.py @@ -338,7 +338,7 @@ class Arbiter(object): continue worker = Worker(i, self.pid, self.LISTENER, self.modname, - self.timeout/2, self.PIPE, self.debug) + self.timeout/2, self.debug) pid = os.fork() if pid != 0: self.WORKERS[pid] = worker diff --git a/gunicorn/worker.py b/gunicorn/worker.py index 6870945f..9f7a65a2 100644 --- a/gunicorn/worker.py +++ b/gunicorn/worker.py @@ -27,8 +27,7 @@ class Worker(object): PIPE = [] - def __init__(self, workerid, ppid, socket, app, - timeout, pipe, debug=False): + def __init__(self, workerid, ppid, socket, app, timeout, debug=False): self.nr = 0 self.id = workerid self.ppid = ppid @@ -44,9 +43,9 @@ class Worker(object): self.spinner = 0 # init pipe - self.PIPE = pipe - map(util.set_non_blocking, pipe) - map(util.close_on_exec, 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) @@ -65,7 +64,8 @@ class Worker(object): signal.signal(signal.SIGINT, self.handle_exit) def handle_usr1(self, sig, frame): - self.nr = -65536; + self.log.info("USR1") + self.nr = -65536; try: map(lambda p: p.close(), self.PIPE) except: @@ -106,10 +106,9 @@ class Worker(object): if e[0] not in (errno.EAGAIN, errno.ECONNABORTED): raise - # Accept until we hit EAGAIN. We're betting that when we're - # processing clients that more clients are waiting. When - # there's no more clients waiting we go back to the select() - # loop and wait for some lovin. + # Keep processing clients until no one is waiting. + # This prevents the need to select() for every + # client that we process. if self.nr > 0: continue