Currently, os module for windows does not have support for sendfile. However, it exists for Windows family of operating systems, but only for sockets.
I think it would be great to close one of the gaps between POSIX operating systems and Windows, at least for that. Here’s windows socket call called TransferFile, which should work similarly as os.sendfile is. TransmitFile at learn.microsoft.com
Fair enough—just to be clear, I have no particular opinion, nor am I particularly qualified on this topic. It just seemed to me that adding missing support for a Tier 1 platform to an existing standard library function (as opposed to, e.g., introducing a whole new function) seemed far enough from a brand new feature driven by conceptual and usability concerns, and close enough to a detail enhancement/defect fix driven by technical and implementation ones, to be a better fit for the issue tracker. However, it’s perfectly possible I’m misjudging this.
IMO, I’m all for reducing the delta between what’s implemented on POSIX platforms vs. on Windows (so long as there aren’t subtle but significant differences we can’t account for that could bite unwary users), so great to see you’re looking in to that. Thanks!
TransmitFile() is supported by the asyncio proactor event loop sendfile() and sock_sendfile() methods. Here’s a snippet of the low-level implementation in “Modules/overlapped.c”:
WSAAsyncSelect() isn’t applicable to implementing select.select(), and it isn’t a good fit for the standard library. It integrates socket I/O into a GUI window message loop. That’s for a GUI toolkit to handle, such as Qt for example:
Thank you a lot for this insight! I didn’t know that WSAAsyncSelect is for GUI window message loop and that TransmitFile is already in!
Starting from which Python version it’s usable for everybody? And additionally - can we use it without asyncio?
Later on I will take a look at other things, like more socket related ioctl methods available on Windows, but not exposed to python
Seen in a vacuum, “only works on sockets” is a pretty significant and annoying difference. But that exact same distinction also applies to quite a few other Windows features (where winsock is its own thing, in contrast to Unix where those features are available on all FDs), making it less confusing.
The Overlapped.TransmitFile() method is implemented in Python 3.7+ in the _overlapped extension module. It’s undocumented and only intended for internal use in the standard library. That said, it’s technically possible to use it outside of the asyncio module, but it’s awkward. For example:
Thanks a lot! I have a question then - if most of the work was done to support this, why it’s not hooked onto os.sendfile? That would make life much easier in terms of code portability etc.
If there’s issue with time needed for somebody to implement it, maybe I might jump in (if it does not involve C too much, my skills are not great ) and implement that for os.sendfile in my rather limited, but still available, spare time