Python是否支持零拷贝I/O? [英] Does Python support zero-copy I/O?
问题描述
我有两个打开的文件对象,分别是 dest
和 src
.打开文件对象 dest
进行写入,将查找位置放置在文件内的某个偏移处,然后打开文件对象 src
进行读取.我需要做的就是简单地从 src
中的当前位置读取到EOF,然后将内容尽快传输到 dest
.
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.
Python还支持零拷贝吗?
Does Python also support zero-copy?
推荐答案
从3.3版开始,Python就有 os.sendfile
,它与各种Unix变体的 sendfile(2)
零拷贝I/O接口连接.它对文件描述符进行操作,而不是对一般的类文件对象进行操作.对于较旧的Python,有 py-sendfile .
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.
这篇关于Python是否支持零拷贝I/O?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!