def recv(self, buffer_size = 65535): try: result = self.socket.recv(buffer_size) #print ("~~~~~~~~~~~~~", len (result), result) if result is None: return b'' elif result == b'': self.handle_close() return b'' else: self.server.bytes_in.increment(len(result)) return result except MemoryError: lifetime.shutdown (1, 1.0) except ssl.SSLError as why: if why.errno == ssl.SSL_ERROR_WANT_READ: try: raise BlockingIOError except NameError: raise socket.error (EWOULDBLOCK) # closed connection elif why.errno in (ssl.SSL_ERROR_ZERO_RETURN, ssl.SSL_ERROR_EOF): self.handle_close () return b'' else: raise
def check_django_reloader(self, now): from django.utils import autoreload changed = autoreload.code_changed() if changed: self.wasc.logger("app", "reloading app, %s" % self.abspath, "debug") self.last_reloaded = time.time() lifetime.shutdown(3, 0)
def recv(self, buffer_size): self.event_time = int(time.time()) try: result = asynchat.async_chat.recv(self, buffer_size) if not result: self.handle_close() return b"" #print ("RECV", repr(result), self.get_terminator ()) lr = len(result) self.server.bytes_in.inc(lr) self.bytes_in.inc(lr) return result except MemoryError: lifetime.shutdown(1, 1.0)
def run(self): while 1: job = self.queue.get() if job is None: break with self.lock: self.idle = 0 self.command = str(job) start_time = time.time() try: job() except MemoryError: self.logger.trace("thread #%d" % self.id) lifetime.shutdown(1, 1.0) except: self.logger.trace("thread #%d" % self.id) exc_time = time.time() - start_time with self.lock: self.exec_time = exc_time self.idle = 1 del job
def hQUITWORKER(signum, frame): lifetime.shutdown(0, 30.0)
def hTERMWORKER(signum, frame): lifetime.shutdown(0, 1.0)
def hHUP(signum, frame): lifetime.shutdown(3, 30.0)
def hTERM(signum, frame): lifetime.shutdown(0, 30.0)
def shutdown(self, timeout=0): lifetime.shutdown(0, timeout)
def restart(self, timeout=0): lifetime.shutdown(3, timeout)