Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

GH-142407: Doc: Clarify shutil.copyfile() does not use CopyFile2 on Windows#144354

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Doc: Clarify that shutil.copyfile() does not use CopyFile2 on Windows
  • Loading branch information
@xiatianxuan
xiatianxuan committedJan 31, 2026
commit67ef1c240ff3a1d34352792836608bf73782245f
14 changes: 11 additions & 3 deletionsDoc/library/shutil.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -538,9 +538,17 @@ On Linux :func:`os.copy_file_range` or :func:`os.sendfile` is used.

On Solaris :func:`os.sendfile` is used.

On Windows :func:`shutil.copyfile` uses a bigger default buffer size (1 MiB
instead of 64 KiB) and a :func:`memoryview`-based variant of
:func:`shutil.copyfileobj` is used.
On Windows, :func:`shutil.copy`, :func:`shutil.copy2`, :func:`shutil.copytree`,
and :func:`shutil.move` use the native ``CopyFile2`` API (available on Windows 8
and later) when possible. This performs the copy entirely in kernel space,
supports copy-on-write, and avoids copying data through userspace buffers,
resulting in significantly better performance—especially for large files or
files on network shares.

In contrast, :func:`shutil.copyfile` does **not** use ``CopyFile2``; it still
performs a userspace read/write loop (albeit with a larger 1 MiB buffer since
Python 3.8). Therefore, for best performance on Windows, prefer :func:`copy2`
over :func:`copyfile` when preserving metadata (like timestamps) is acceptable.

If the fast-copy operation fails and no data was written in the destination
file then shutil will silently fallback on using less efficient
Expand Down
Loading

[8]ページ先頭

©2009-2026 Movatter.jp