def init_process(self): """\ If you override this method in a subclass, the last statement in the function should be to call this method with super(MyWorkerClass, self).init_process() so that the ``run()`` loop is initiated. """ util.set_owner_process(self.conf.get("uid", os.geteuid()), self.conf.get("gid", os.getegid())) # Reseed the random number generator util.seed() # For waking ourselves up self._PIPE = os.pipe() map(util.set_non_blocking, self._PIPE) map(util.close_on_exec, self._PIPE) # Prevent fd inherientence util.close_on_exec(self.tmp.fileno()) self.init_signals() self.on_init_process() # Enter main run loop self.booted = True self.run()
def init_process(self): """\ If you override this method in a subclass, the last statement in the function should be to call this method with super(MyWorkerClass, self).init_process() so that the ``run()`` loop is initiated. """ # set current pid self.pid = os.getpid() util.set_owner_process(self.conf.get("uid", os.geteuid()), self.conf.get("gid", os.getegid())) # Reseed the random number generator util.seed() # prevent fd inheritance util.close_on_exec(self.tmp.fileno()) # init signals self.init_signals() util._setproctitle("arbiter [%s]" % self.name) self.on_init_process() log.debug("Arbiter %s booted on %s", self.name, self.pid) self.when_ready() # Enter main run loop self.booted = True self.run()
def run(self): self.socket.setblocking(0) while self.alive: self.notify() # Accept a connection. If we get an error telling us # that no connection is waiting we fall down to the # select which is where we'll wait for a bit for new # workers to come give us some love. try: client, addr = self.socket.accept() client.setblocking(1) util.close_on_exec(client) self.handle(client, addr) # Keep processing clients until no one is waiting. This # prevents the need to select() for every client that we # process. continue except socket.error as e: if hasattr(e, 'errno'): v_err = e.errno else: v_err = e[0] if v_err not in (errno.EAGAIN, errno.ECONNABORTED): raise # If our parent changed then we shut down. if self.ppid != os.getppid(): log.info("Parent changed, shutting down: %s", self) return try: self.notify() ret = select.select([self.socket], [], self._PIPE, self.timeout / 2.0) if ret[0]: continue except select.error as e: if hasattr(e, 'errno'): v_err = e.errno else: v_err = e[0] if v_err == errno.EINTR: continue if v_err == errno.EBADF: if self.nr < 0: continue else: return raise
def run(self): self.socket.setblocking(0) while self.alive: self.notify() # Accept a connection. If we get an error telling us # that no connection is waiting we fall down to the # select which is where we'll wait for a bit for new # workers to come give us some love. try: client, addr = self.socket.accept() client.setblocking(1) util.close_on_exec(client) self.handle(client, addr) # Keep processing clients until no one is waiting. This # prevents the need to select() for every client that we # process. continue except socket.error, e: if e[0] not in (errno.EAGAIN, errno.ECONNABORTED): raise # If our parent changed then we shut down. if self.ppid != os.getppid(): log.info("Parent changed, shutting down: %s", self) return try: self.notify() ret = select.select([self.socket], [], self._PIPE, self.timeout / 2.0) if ret[0]: continue except select.error, e: if e[0] == errno.EINTR: continue if e[0] == errno.EBADF: if self.nr < 0: continue else: return raise
def on_init_process(self): self.socket = self.conf.get('sock') self.address = self.socket.getsockname() util.close_on_exec(self.socket)