Staging
v0.5.1
https://github.com/python/cpython
Revision 0a1ff24acfc15d8c7f2dc41000a6f3d9a31e7480 authored by Neil Schemenauer on 22 September 2017, 17:17:30 UTC, committed by GitHub on 22 September 2017, 17:17:30 UTC
* Maintain a list of BufferedWriter objects.  Flush them on exit.

In Python 3, the buffer and the underlying file object are separate
and so the order in which objects are finalized matters.  This is
unlike Python 2 where the file and buffer were a single object and
finalization was done for both at the same time.  In Python 3, if
the file is finalized and closed before the buffer then the data in
the buffer is lost.

This change adds a doubly linked list of open file buffers.  An atexit
hook ensures they are flushed before proceeding with interpreter
shutdown.  This is addition does not remove the need to properly close
files as there are other reasons why buffered data could get lost during
finalization.

Initial patch by Armin Rigo.

* Use weakref.WeakSet instead of WeakKeyDictionary.

* Simplify buffered double-linked list types.

* In _flush_all_writers(), suppress errors from flush().

* Remove NEWS entry, use blurb.

* Take more care when flushing file buffers from atexit.

The previous implementation was not careful enough to avoid
causing issues in multi-threaded cases.  Check for buf->ok
and buf->finalizing before actually doing the flush.  Also,
increase the refcnt to ensure the object does not disappear.
1 parent da9b4cf
History
Tip revision: 0a1ff24acfc15d8c7f2dc41000a6f3d9a31e7480 authored by Neil Schemenauer on 22 September 2017, 17:17:30 UTC
bpo-17852: Maintain a list of BufferedWriter objects. Flush them on exit. (#3372)
Tip revision: 0a1ff24
File Mode Size
.github
Doc
Grammar
Include
Lib
Mac
Misc
Modules
Objects
PC
PCbuild
Parser
Programs
Python
Tools
.gitattributes -rw-r--r-- 733 bytes
.gitignore -rw-r--r-- 1.4 KB
.hgeol -rw-r--r-- 1.0 KB
.hgignore -rw-r--r-- 1.3 KB
.hgtags -rw-r--r-- 8.7 KB
.travis.yml -rw-r--r-- 4.3 KB
LICENSE -rw-r--r-- 12.5 KB
Makefile.pre.in -rw-r--r-- 59.2 KB
README.rst -rw-r--r-- 9.1 KB
aclocal.m4 -rw-r--r-- 10.7 KB
config.guess -rwxr-xr-x 43.2 KB
config.sub -rwxr-xr-x 35.7 KB
configure -rwxr-xr-x 469.5 KB
configure.ac -rw-r--r-- 155.0 KB
install-sh -rwxr-xr-x 7.0 KB
pyconfig.h.in -rw-r--r-- 40.3 KB
setup.py -rw-r--r-- 97.6 KB

README.rst

back to top