def run(self): self.socket.setblocking(1) env = self.base_env.copy() env.update({ 'SERVER_NAME': self.address[0], 'SERVER_PORT': str(self.address[1]) }) self.base_env = env http = core.http() http.set_gencb(self.handle_request) self.pool = Pool(self.worker_connections) self.application = self.wsgi acceptor = gevent.spawn(http.accept, self.socket.fileno()) try: while self.alive: self.notify() if self.ppid != os.getppid(): self.log.info("Parent changed, shutting down: %s" % self) gevent.kill(acceptor) break gevent.sleep(0.1) self.pool.join(timeout=self.timeout) except KeyboardInterrupt: pass
def __init__(self, handle=None, spawn='default'): self.listeners = [] self._stopped_event = Event() self._no_connections_event = Event() self._requests = {} # maps connection -> list of requests self.http = core.http() self.http.set_gencb(self._cb_request) if handle is not None: self.handle = handle if spawn != 'default': self.spawn = spawn
def start_accepting(self): self.http = core.http(self._on_request, self.default_response_headers) self.http.accept(self.socket.fileno())