Does Python support zero-copy I/O?

后端 未结 2 1330
广开言路
广开言路 2021-02-13 19:37

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 th

2条回答
  •  爱一瞬间的悲伤
    2021-02-13 20:21

    Since Python 3.8, you can use shutil.copyfile (and others from shutil) which will internally use zero-copy if possible, such as os.sendfile, and if not possible, fall back to a simple read-write loop.

    See the shutil docs for details. Or issue 33671 (Efficient zero-copy for shutil.copy* functions (Linux, OSX and Win)). And the corresponding (merged) pull request.

    You might also be interested in copy-on-write support or server-side copy support. See here, here. The os.copy_file_range (since Python 3.8) would do that. See issue 37159 (Use copy_file_range() in shutil.copyfile()) (maybe Python 3.9 or 3.10).

提交回复
热议问题