cpython (3.2): Issue #13872: socket.detach() now marks the socket closed (as mirrored in the
http://hg.python.org/cpython/rev/3a220feafa15 changeset: 76033:3a220feafa15 branch: 3.2 parent: 76030:f96b603278cc user: Antoine Pitrou <solipsis@pitrou.net> date: Sun Apr 01 01:00:17 2012 +0200 summary: Issue #13872: socket.detach() now marks the socket closed (as mirrored in the socket repr()). Patch by Matt Joiner. files: Lib/socket.py | 11 +++++++++++ Lib/test/test_socket.py | 1 + Misc/NEWS | 3 +++ 3 files changed, 15 insertions(+), 0 deletions(-) diff --git a/Lib/socket.py b/Lib/socket.py --- a/Lib/socket.py +++ b/Lib/socket.py @@ -197,6 +197,17 @@ 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 --- a/Lib/test/test_socket.py +++ b/Lib/test/test_socket.py @@ -951,6 +951,7 @@ 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) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -31,6 +31,9 @@ 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. -- Repository URL: http://hg.python.org/cpython
participants (1)
-
antoine.pitrou