This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author christian.heimes
Recipients YoSTEALTH, christian.heimes, martin.panter, pitrou, r.david.murray, vstinner, yselivanov
Date 2018-02-24.09:50:34
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1519465834.85.0.467229070634.issue28134@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2018-02-24 09:50:34christian.heimessetrecipients: + christian.heimes, pitrou, vstinner, r.david.murray, martin.panter, yselivanov, YoSTEALTH
2018-02-24 09:50:34christian.heimessetmessageid: <1519465834.85.0.467229070634.issue28134@psf.upfronthosting.co.za>
2018-02-24 09:50:34christian.heimeslinkissue28134 messages
2018-02-24 09:50:34christian.heimescreate