我们从Python开源项目中,提取了以下5个代码示例,用于说明如何使用gevent.socket.recv()。
def listen(self, socket): while True: data = socket.recv(1024) print(data) if data == b'\n': self.shutdown()
def handle(self): """ The main request handling method, called by the server. This method runs a request handling loop, calling :meth:`handle_one_request` until all requests on the connection have been handled (that is, it implements keep-alive). """ try: while self.socket is not None: self.time_start = time.time() self.time_finish = 0 result = self.handle_one_request() if result is None: break if result is True: continue self.status, response_body = result self.socket.sendall(response_body) if self.time_finish == 0: self.time_finish = time.time() self.log_request() break finally: if self.socket is not None: _sock = getattr(self.socket, '_sock', None) # Python 3 try: # read out request data to prevent error: [Errno 104] Connection reset by peer if _sock: try: # socket.recv would hang _sock.recv(16384) finally: _sock.close() self.socket.close() except socket.error: pass self.__dict__.pop('socket', None) self.__dict__.pop('rfile', None)