https://github.com/python/cpython/commit/34393cbdd46fd965de86f1e7bc89ab111f506723
commit: 34393cbdd46fd965de86f1e7bc89ab111f506723
branch: main
author: Russell Keith-Magee <[email protected]>
committer: freakboy3742 <[email protected]>
date: 2025-06-24T08:55:50+08:00
summary:

gh-135648: Document that `shutil.copyfileobj` doesn't flush (#135737)

Adds a note about flush/close on copyfileobj, and updates 
the Emscripten build script to follow documented advice.

files:
M Doc/library/shutil.rst
M Tools/wasm/emscripten/__main__.py

diff --git a/Doc/library/shutil.rst b/Doc/library/shutil.rst
index e7c4c4f46bd011..2dde40c9d92f45 100644
--- a/Doc/library/shutil.rst
+++ b/Doc/library/shutil.rst
@@ -47,6 +47,13 @@ Directory and files operations
    0, only the contents from the current file position to the end of the file 
will
    be copied.
 
+   :func:`copyfileobj` will *not* guarantee that the destination stream has
+   been flushed on completion of the copy. If you want to read from the
+   destination at the completion of the copy operation (for example, reading
+   the contents of a temporary file that has been copied from a HTTP stream),
+   you must ensure that you have called :func:`~io.IOBase.flush` or
+   :func:`~io.IOBase.close` on the file-like object before attempting to read
+   the destination file.
 
 .. function:: copyfile(src, dst, *, follow_symlinks=True)
 
diff --git a/Tools/wasm/emscripten/__main__.py 
b/Tools/wasm/emscripten/__main__.py
index 849bd5de44eb7b..c0d58aeaadd2cf 100644
--- a/Tools/wasm/emscripten/__main__.py
+++ b/Tools/wasm/emscripten/__main__.py
@@ -167,11 +167,12 @@ def make_build_python(context, working_dir):
 @subdir(HOST_BUILD_DIR, clean_ok=True)
 def make_emscripten_libffi(context, working_dir):
     shutil.rmtree(working_dir / "libffi-3.4.6", ignore_errors=True)
-    with tempfile.NamedTemporaryFile(suffix=".tar.gz") as tmp_file:
+    with tempfile.NamedTemporaryFile(suffix=".tar.gz", delete_on_close=False) 
as tmp_file:
         with urlopen(
             
"https://github.com/libffi/libffi/releases/download/v3.4.6/libffi-3.4.6.tar.gz";
         ) as response:
             shutil.copyfileobj(response, tmp_file)
+        tmp_file.close()
         shutil.unpack_archive(tmp_file.name, working_dir)
     call(
         [EMSCRIPTEN_DIR / "make_libffi.sh"],

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to