Index: Misc/ACKS =================================================================== --- Misc/ACKS (révision 87637) +++ Misc/ACKS (copie de travail) @@ -131,6 +131,7 @@ Daniel Calvelo Tony Campbell Brett Cannon +Justin Cappos Mike Carlton Terry Carroll Lorenzo M. Catucci Index: Misc/NEWS =================================================================== --- Misc/NEWS (révision 87637) +++ Misc/NEWS (copie de travail) @@ -20,6 +20,11 @@ Library ------- +- Issue #7995: Fix that the socket returned from socket.accept() must not + inherit the listening socket's file status flags; otherwise the returned + socket could end up non-blocking if the listening socket had a timeout. + Patch by Ross Lagerwall. + - Issue #10801: In zipfile, support different encodings for the header and the filenames. Index: Lib/socket.py =================================================================== --- Lib/socket.py (révision 87637) +++ Lib/socket.py (copie de travail) @@ -130,7 +130,10 @@ For IP sockets, the address info is a pair (hostaddr, port). """ fd, addr = self._accept() - return socket(self.family, self.type, self.proto, fileno=fd), addr + sock = socket(self.family, self.type, self.proto, fileno=fd) + if self.gettimeout(): + sock.setblocking(True) + return sock, addr def makefile(self, mode="r", buffering=None, *, encoding=None, errors=None, newline=None): Index: Lib/test/test_socket.py =================================================================== --- Lib/test/test_socket.py (révision 87637) +++ Lib/test/test_socket.py (copie de travail) @@ -976,6 +976,23 @@ def _testInitNonBlocking(self): pass + def testInheritFlags(self): + # Issue #7995: when calling accept() on a listening socket with a + # timeout, the resulting socket should not be non-blocking. + self.serv.settimeout(10) + try: + conn, addr = self.serv.accept() + message = conn.recv(len(MSG)) + finally: + conn.close() + self.serv.settimeout(None) + + def _testInheritFlags(self): + time.sleep(0.1) + self.cli.connect((HOST, self.port)) + time.sleep(0.5) + self.cli.send(MSG) + def testAccept(self): # Testing non-blocking accept self.serv.setblocking(0)