mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Issue #13872: socket.detach() now marks the socket closed (as mirrored in the socket repr()).
Patch by Matt Joiner.
This commit is contained in:
commit
8315f96764
3 changed files with 15 additions and 0 deletions
|
@ -199,6 +199,17 @@ class socket(_socket.socket):
|
||||||
if self._io_refs <= 0:
|
if self._io_refs <= 0:
|
||||||
self._real_close()
|
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):
|
def fromfd(fd, family, type, proto=0):
|
||||||
""" fromfd(fd, family, type[, proto]) -> socket object
|
""" fromfd(fd, family, type[, proto]) -> socket object
|
||||||
|
|
||||||
|
|
|
@ -1574,6 +1574,7 @@ class BasicTCPTest(SocketConnectedTest):
|
||||||
f = self.cli_conn.detach()
|
f = self.cli_conn.detach()
|
||||||
self.assertEqual(f, fileno)
|
self.assertEqual(f, fileno)
|
||||||
# cli_conn cannot be used anymore...
|
# cli_conn cannot be used anymore...
|
||||||
|
self.assertTrue(self.cli_conn._closed)
|
||||||
self.assertRaises(socket.error, self.cli_conn.recv, 1024)
|
self.assertRaises(socket.error, self.cli_conn.recv, 1024)
|
||||||
self.cli_conn.close()
|
self.cli_conn.close()
|
||||||
# ...but we can create another socket using the (still open)
|
# ...but we can create another socket using the (still open)
|
||||||
|
|
|
@ -37,6 +37,9 @@ Core and Builtins
|
||||||
Library
|
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(
|
- Issue #14406: Fix a race condition when using ``concurrent.futures.wait(
|
||||||
return_when=ALL_COMPLETED)``. Patch by Matt Joiner.
|
return_when=ALL_COMPLETED)``. Patch by Matt Joiner.
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue