# HG changeset patch # User Kristján Valur Jónsson # Date 1331767402 25200 # Node ID 22b685c467c3177c54cd293168d53cf5d9a8624b # Parent aac602bd8ec39e39c4fd74257bef6cabc574dbe0 socketserver with no select diff --git a/Lib/socketserver.py b/Lib/socketserver.py --- a/Lib/socketserver.py +++ b/Lib/socketserver.py @@ -286,19 +286,28 @@ self.shutdown_request(request) def _get_request_timeout(self, timeout): - """Get one request, with timeout.""" - # Support people who used socket.settimeout() to escape - # handle_request before self.timeout was available. - sock_timeout = self.socket.gettimeout() - if timeout is None: - timeout = sock_timeout - elif sock_timeout is not None: - timeout = min(timeout, sock_timeout) - #use select so that we don't have to mess with the attributes - #of sockets or catch timeout exceptions. - fd_sets = select.select([self], [], [], timeout) - if not fd_sets[0]: - return None + """Get one request, possibly timing out with socket.timeout. + Make sure to not change the socket's timeout property + permanently. The socket's timeout takes precedence if it + is lower. + """ + if timeout is not None: + stored = self.socket.gettimeout() + #use the socket timeout if it was lower. This is to + #support people that use socket.settimeout(). + if stored is None or stored > timeout: + #temporarily change the timeout of the listenin socket + self.socket.settimeout(timeout) + try: + request, client_addr = self.get_request() + #enforce timeout inheritance + try: + request.settimeout(stored) + except AttributeError: + pass + return request, client_addr + finally: + self.socket.settimeout(stored) return self.get_request() def handle_timeout(self):