]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #13872: socket.detach() now marks the socket closed (as mirrored in the socket...
authorAntoine Pitrou <solipsis@pitrou.net>
Sat, 31 Mar 2012 23:00:17 +0000 (01:00 +0200)
committerAntoine Pitrou <solipsis@pitrou.net>
Sat, 31 Mar 2012 23:00:17 +0000 (01:00 +0200)
Patch by Matt Joiner.

Lib/socket.py
Lib/test/test_socket.py
Misc/NEWS

index 1e285493c48e289687d9c73e98ab35f92219c34f..a93cd11248c7a041c712a06b6ca6c1403de45589 100644 (file)
@@ -197,6 +197,17 @@ class socket(_socket.socket):
         if self._io_refs <= 0:
             self._real_close()
 
+    def detach(self):
+        """detach() -> file descriptor
+
+        Close the socket object without closing the underlying file descriptor.
+        The object cannot be used after this call, but the file descriptor
+        can be reused for other purposes.  The file descriptor is returned.
+        """
+        self._closed = True
+        return super().detach()
+
+
 def fromfd(fd, family, type, proto=0):
     """ fromfd(fd, family, type[, proto]) -> socket object
 
index d77b7dc9ed648f8fd0134b520458c1a8745d0c13..cce0d1b6eb4f917ddcc6611ed820b7371bed9224 100644 (file)
@@ -951,6 +951,7 @@ class BasicTCPTest(SocketConnectedTest):
         f = self.cli_conn.detach()
         self.assertEqual(f, fileno)
         # cli_conn cannot be used anymore...
+        self.assertTrue(self.cli_conn._closed)
         self.assertRaises(socket.error, self.cli_conn.recv, 1024)
         self.cli_conn.close()
         # ...but we can create another socket using the (still open)
index 07eea7297675c6699b92ae1bc3159493cbedbad7..32c0b9edc4292f342aa1f5cfff8d36988745dae8 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -31,6 +31,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #13872: socket.detach() now marks the socket closed (as mirrored
+  in the socket repr()).  Patch by Matt Joiner.
+
 - Issue #14406: Fix a race condition when using ``concurrent.futures.wait(
   return_when=ALL_COMPLETED)``.  Patch by Matt Joiner.