(original) (raw)
changeset: 76033:3a220feafa15 branch: 3.2 parent: 76030:f96b603278cc user: Antoine Pitrou solipsis@pitrou.net date: Sun Apr 01 01:00:17 2012 +0200 files: Lib/socket.py Lib/test/test_socket.py Misc/NEWS description: Issue #13872: socket.detach() now marks the socket closed (as mirrored in the socket repr()). Patch by Matt Joiner. diff -r f96b603278cc -r 3a220feafa15 Lib/socket.py --- a/Lib/socket.py Sat Mar 31 23:50:31 2012 +0200 +++ b/Lib/socket.py Sun Apr 01 01:00:17 2012 +0200 @@ -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 -r f96b603278cc -r 3a220feafa15 Lib/test/test_socket.py --- a/Lib/test/test_socket.py Sat Mar 31 23:50:31 2012 +0200 +++ b/Lib/test/test_socket.py Sun Apr 01 01:00:17 2012 +0200 @@ -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 -r f96b603278cc -r 3a220feafa15 Misc/NEWS --- a/Misc/NEWS Sat Mar 31 23:50:31 2012 +0200 +++ b/Misc/NEWS Sun Apr 01 01:00:17 2012 +0200 @@ -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. /solipsis@pitrou.net