Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Python support zero-copy I/O?

I have two open file objects, dest and src. File object dest is opened for writing, with the seek position placed at some offset within the file, and file object src is opened for reading. What I need to do is simply read from the current position in src to EOF and transfer the contents to dest as quickly as possible.

If I were programming in Java, I could utilize the FileChannel#transferTo() method to perform zero-copy file I/O.

Does Python also support zero-copy?

like image 421
Daniel Trebbien Avatar asked Sep 17 '11 16:09

Daniel Trebbien


1 Answers

Since version 3.3, Python has os.sendfile, which interfaces to various Unix variants' sendfile(2) zero-copy I/O interfaces. It operates on file descriptors, not general file-like objects. For older Pythons, there's py-sendfile.

like image 63
Fred Foo Avatar answered Sep 18 '22 00:09

Fred Foo