[Python-Dev] Add sendfile() to core?

Giampaolo Rodolà g.rodola at gmail.com
Sun Jan 9 21:09:40 CET 2011


A strong +1.
Projects such as Twisted would certainly benefit from such an addiction.
I'm not sure the os module is the right place for sendfile() to land though.
Implementation between different platforms tends to vary quite a bit.
A good resource is the samba source code which contains an
implementation for all major UNIX systems.


--- Giampaolo
http://code.google.com/p/pyftpdlib/
http://code.google.com/p/psutil/


2011/1/8 max ulidtko <ulidtko at gmail.com>:
> 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, [1]).
>
> 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
> another """
>    sofar = 0
>    while sofar < length:
>        amount = blocksize if sofar + blocksize <= length \
>                           else length - sofar
>        file2.write(file1.read(amount))
>        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.
>
> [1] http://mail.python.org/pipermail/python-dev/2002-March/021543.html
>
> ------
> Sincerely,
> max ulidtko
>
> _______________________________________________
> Python-Dev mailing list
> Python-Dev at python.org
> http://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe: http://mail.python.org/mailman/options/python-dev/g.rodola%40gmail.com
>


More information about the Python-Dev mailing list