diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2012-03-31 23:00:17 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2012-03-31 23:00:17 (GMT) |
commit | 70deb3de3960142fcf8497d2ea0cfae6609b8e66 (patch) | |
tree | 15cb6d93f031cd47f105af9522666f3fa8631b7a | |
parent | 6211b881613de6654ec8b5e77f3c705f1b4becb8 (diff) | |
download | cpython-70deb3de3960142fcf8497d2ea0cfae6609b8e66.zip cpython-70deb3de3960142fcf8497d2ea0cfae6609b8e66.tar.gz cpython-70deb3de3960142fcf8497d2ea0cfae6609b8e66.tar.bz2 |
Issue #13872: socket.detach() now marks the socket closed (as mirrored in the socket repr()).
Patch by Matt Joiner.
-rw-r--r-- | Lib/socket.py | 11 | ||||
-rw-r--r-- | Lib/test/test_socket.py | 1 | ||||
-rw-r--r-- | Misc/NEWS | 3 |
3 files changed, 15 insertions, 0 deletions
diff --git a/Lib/socket.py b/Lib/socket.py index 1e28549..a93cd11 100644 --- a/Lib/socket.py +++ b/Lib/socket.py @@ -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 diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py index d77b7dc..cce0d1b 100644 --- a/Lib/test/test_socket.py +++ b/Lib/test/test_socket.py @@ -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) @@ -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. |