Skip to content

Commit e3766fd

Browse files
committed
Add note about flush/close on copyfileobj.
1 parent c8c13f8 commit e3766fd

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

Doc/library/shutil.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@ Directory and files operations
4747
0, only the contents from the current file position to the end of the file will
4848
be copied.
4949

50+
:func:`copyfileobj` will *not* guarantee that the destination stream has
51+
been flushed on completion of the copy. If you want to read from the
52+
destination at the completion of the copy operation (for example, reading
53+
the contents of a temporary file that has been copied from a HTTP stream),
54+
you must ensure that you have called :func:`~io.IOBase.flush` or
55+
:func:`~io.IOBase.close` on the file-like object before attempting to read
56+
the destination file.
5057

5158
.. function:: copyfile(src, dst, *, follow_symlinks=True)
5259

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
The documentation for :func:`shutil.copyfileobj` now warns the user of the
2+
need to close or flush the destination stream on completion.

0 commit comments

Comments
 (0)