[Python-ideas] PEP 3156: Transport.sendfile (original) (raw)

Guido van Rossum guido at python.org
Fri Jan 25 21:28:28 CET 2013


On Fri, Jan 25, 2013 at 12:25 PM, Nikolay Kim <fafhrd91 at gmail.com> wrote:

On Jan 25, 2013, at 12:04 PM, Guido van Rossum <guido at python.org> wrote: On Fri, Jan 25, 2013 at 10:11 AM, Nikolay Kim <fafhrd91 at gmail.com> wrote:

On Jan 25, 2013, at 10:08 AM, Guido van Rossum <guido at python.org> wrote: On Fri, Jan 25, 2013 at 10:03 AM, Nikolay Kim <fafhrd91 at gmail.com> wrote:

I think Transport needs 'sendfile' api, something like: @tasks.coroutine def sendfile(self, fd, offset, nbytes): …. otherwise it is impossible to implement sendfile without breaking transport encapsulation Really? Can't the user write this themselves? What's wrong with this: while True: data = os.read(fd, 16*1024) if not data: break transport.write(data) (Perhaps augmented with a way to respond to pause() requests.) i mean 'os.sendfile()', zero-copy sendfile. I see (http://docs.python.org/dev/library/os.html#os.sendfile). Hm, that function is so platform-specific that we might as well force users to do it this way: sock = transport.getextrainfo("socket") if sock is not None: os.sendfile(sock.fileno(), ......) else: <use write() like I suggested above> there should some kind of way to flush write buffer or write callbacks. sock = transport.getextrainfo("socket") if sock is not None: os.sendfile(sock.fileno(), ......) else: yield from transport.writebufferflush() <use of write() method>

Oh, that's an interesting idea in its own right. But I'm not sure Twisted could implement this given that their flow control works differently.

However, I think you've convinced me that offering sendfile() is actually better. But should it take a file descriptor or a stream (file) object?

-- --Guido van Rossum (python.org/~guido) -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130125/32cbd835/attachment.html>



More information about the Python-ideas mailing list