Index: Lib/test/test_socket.py =================================================================== --- Lib/test/test_socket.py (révision 87735) +++ 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) Index: Modules/socketmodule.c =================================================================== --- Modules/socketmodule.c (révision 87735) +++ Modules/socketmodule.c (copie de travail) @@ -781,8 +781,12 @@ #endif { s->sock_timeout = defaulttimeout; - if (defaulttimeout >= 0.0) - internal_setblocking(s, 0); + /* Issue #7995: On many platforms (BSD, Solaris, Windows), sockets + from accept() inherit the blocking property from the listening + socket. On other platforms (like Linux), this property is + not inherited. Therefore, we set the blocking property + explicitly on all new socket objects. */ + internal_setblocking(s, defaulttimeout < 0); } }