[issue28134] socket.socket(fileno=fd) does not work as documented
Christian Heimes
report at bugs.python.org
Sat Feb 24 04:50:34 EST 2018
Christian Heimes <lists at cheimes.de> added the comment:
File descriptors are a advanced features and expose low level operating system resources. You really have to understand how the OS works. They cannot be reference counted. In fact they *are* the reference to entries in the Kernel's global open file table. I gave a talked about FDs at PyCon US two years ago, maybe https://speakerdeck.com/tiran/pycon-2016-file-descriptors-unix-sockets-and-other-posix-magic will help you understand fds better.
You can make your example work with https://docs.python.org/3/library/socket.html#socket.socket.detach
def accept(sock):
client, addr = sock.accept()
inside = socket(fileno=client.fileno())
client.detach()
print(inside)
return inside
# after return, the client socket is closed by due to detach the fd isn't no longer close
The feature works as intended. It's designed to turn an inherited file descriptor (e.g. systemd socket activation) or transfered fds (e.g. through AF_UNIX SCM_RIGHTS). In both cases the fd is already a duplicated fd.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue28134>
_______________________________________
More information about the Python-bugs-list
mailing list