[Python-ideas] Addition to I/O stack: send()

Giovanni Bajo rasky at develer.com
Sat Apr 18 18:05:13 CEST 2009


currently, Python has no builtin way to "copy a file object into 
another", an operation commonly referred to as "send". I think this would 
be a good addition to the I/O stack.

To make things clearer, this is pseudo-code of what I meant:

   def send(self, out):
       while 1:
           data = self.read(4096)
           if not data:

I'll notice that the implementation can be tweaked in different ways:

 * Some operating systems do support this operation natively (through 
syscalls like "sendfile"), which is faster because the data does not 
roundtrips to user space. This is useful eg. for webservers serving files 
to network.

 * In the user-space implementation, the buffer size could match whatever 
buffer already exists for a buffered file reader (eg: BufferedIOBase and 

Because of these different details, I think it would be a good addition 
to the I/O stack. Though, I don't fully understand it yet as to provide a 
more concrete proposals as where to put each different possible 

Also, I'm unsure how this could couple with different kind of files 
(pipes, sockets, etc.). As far as I can tell, the new I/O stack is not 
used by the standard socket library yet, for instance.
Giovanni Bajo
Develer S.r.l.

More information about the Python-ideas mailing list