cpython/Modules/_io
Neil Schemenauer 0a1ff24acf bpo-17852: Maintain a list of BufferedWriter objects. Flush them on exit. (#3372)
* 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.
2017-09-22 10:17:30 -07:00
..
clinic bpo-29464: Rename METH_FASTCALL to METH_FASTCALL|METH_KEYWORDS and make (#1955) 2017-07-03 21:20:15 +03:00
_iomodule.c bpo-17852: Maintain a list of BufferedWriter objects. Flush them on exit. (#3372) 2017-09-22 10:17:30 -07:00
_iomodule.h bpo-17852: Maintain a list of BufferedWriter objects. Flush them on exit. (#3372) 2017-09-22 10:17:30 -07:00
bufferedio.c bpo-17852: Maintain a list of BufferedWriter objects. Flush them on exit. (#3372) 2017-09-22 10:17:30 -07:00
bytesio.c bpo-31095: fix potential crash during GC (GH-2974) 2017-08-24 14:55:17 +09:00
fileio.c [security] bpo-13617: Reject embedded null characters in wchar* strings. (#2302) 2017-06-28 08:30:06 +03:00
iobase.c bpo-30061: Check if PyObject_Size()/PySequence_Size()/PyMapping_Size() (#1096) 2017-04-19 20:03:52 +03:00
stringio.c bpo-30022: Get rid of using EnvironmentError and IOError (except test… (#1051) 2017-04-16 10:46:38 +03:00
textio.c bpo-31243: Fixed PyArg_ParseTuple failure checks. (#3171) 2017-08-29 11:58:27 +03:00
winconsoleio.c bpo-30708: Check for null characters in PyUnicode_AsWideCharString(). (#2285) 2017-06-27 16:03:14 +03:00