Martin Panter added the comment: Yes, I think this is the expected behaviour, and I can’t think of any improvements that could be made. If you call fileno(), you have to ensure that you don’t close the file descriptor until you have finished using it. It is a bit like accessing memory after it has been freed. Python doesn’t make raw memory addresses easily accessible, but it does make fileno() accessible without much protection.
Perhaps there is some confusion about the term socket. Normally (without using the fileno=... parameter), Python’s socket() constructor does two things. First, it creates a new OS socket using the socket() system call (or Winsock equivalent), which returns a file descriptor or handle (an integer). Then, it creates a Python socket object, which wraps the file descriptor. When you use socket(fileno=...), only the second step is taken. You get a _new_ socket object, which wraps the given existing OS socket file descriptor. So when it says “the same socket”, I think it means the same OS-level socket. It still creates a new Python object. ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue26703> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com