Skip to content

Commit 4a44f53

Browse files
[3.9] bpo-17852: Doc: Fix the tutorial about closing files (GH-23135) (GH-23527)
Co-authored-by: Inada Naoki <songofacandy@gmail.com> (cherry picked from commit c8aaf71) Co-authored-by: Volker-Weissmann <39418860+Volker-Weissmann@users.noreply.github.com>
1 parent aef482f commit 4a44f53

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

Doc/tutorial/inputoutput.rst

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -329,11 +329,16 @@ equivalent :keyword:`try`\ -\ :keyword:`finally` blocks::
329329

330330
If you're not using the :keyword:`with` keyword, then you should call
331331
``f.close()`` to close the file and immediately free up any system
332-
resources used by it. If you don't explicitly close a file, Python's
333-
garbage collector will eventually destroy the object and close the
334-
open file for you, but the file may stay open for a while. Another
335-
risk is that different Python implementations will do this clean-up at
336-
different times.
332+
resources used by it.
333+
334+
.. warning::
335+
Calling ``f.write()`` without using the :keyword:`!with` keyword or calling
336+
``f.close()`` **might** result in the arguments
337+
of ``f.write()`` not being completely written to the disk, even if the
338+
program exits successfully.
339+
340+
..
341+
See also https://bugs.python.org/issue17852
337342
338343
After a file object is closed, either by a :keyword:`with` statement
339344
or by calling ``f.close()``, attempts to use the file object will

0 commit comments

Comments
 (0)