Index: Lib/socket.py =================================================================== --- Lib/socket.py (révision 87761) +++ Lib/socket.py (copie de travail) @@ -130,7 +130,13 @@ 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) + # Issue #7995: if no default timeout is set and the listening + # socket had a (non-zero) timeout, force the new socket in blocking + # mode to override platform-specific socket flags inheritance. + if getdefaulttimeout() is None and 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 87761) +++ Lib/test/test_socket.py (copie de travail) @@ -982,6 +982,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)