[Python-Dev] Add sendfile() to core?
ulidtko at gmail.com
Sat Jan 8 08:55:19 CET 2011
On Wed, 20 Mar 2002 14:53:58 -0500, Andrew Kuchling wrote:
| sendfile() is used when writing really high-performance Web servers,
| in order to save an unnecessary memory-to-memory copy. Question:
| should I make up a patch to add a sendfile() wrapper to Python?
So, was this proposal rejected? If so, for what reasons?
Wrapper of such a useful call would be of great convenience, especially
considering its availability on Win32 (see Thomas Heller's notice, ).
Anyway, when one needs to send (arbitrarily large) files to a socket and
back, ugly and slow workarounds are born, like this one:
def copy_file(file1, file2, length, blocksize=40960):
""" Transfer exactly length bytes from one file-like object to
sofar = 0
while sofar < length:
amount = blocksize if sofar + blocksize <= length \
else length - sofar
sofar += amount
Using hypothetical os.sendfile() would be so much better!
The only difficulty I can see is the choice of name for the wrapper.
IMO, using "sendfile" from Linux and FreeBSD is pretty much okay; but
objections may arise.
More information about the Python-Dev