Open jameslan opened 4 years ago
For the TextIOWrapper
it seems like flush
is called by __del__
:
import io
class Test(io.TextIOWrapper):
def __del__(self):
pass
out = Test(io.BufferedWriter(io.FileIO('test.txt', 'w')))
out.write('a')
Probably similar for io.FileIO
. For writing to standard streams it looks like CPython calls flush
on sys.stdout
and sys.stderr
during Py_FinalizeEx
. See https://github.com/python/cpython/blob/6c065594c720fdd4783a4284cb9f2eebcb2c10bd/Python/pylifecycle.c#L480-L502
sys.stdout
is TextIOWrapper(BufferedWriter(FileIO(Console.OpenStandardOutput())))
and sys.stderr
is TextIOWrapper(BufferedWriter(FileIO(Console.OpenStandardError())))
So I think if TextIOWrapper
or BufferedWriter
could flush at exit, sys.stdout
and sys.stderr
should be good.
stdio are created here https://github.com/IronLanguages/ironpython3/blob/f32bf73f364c176db5cbbb6cefc6ec5f9fc92934/Src/IronPython/Runtime/PythonContext.cs#L1830-L1834
ipy
, will get an empty filetest.txt
, while with CPython, the file will have one byte 'a'BufferedWriter
:The following powershell command output nothing,
and the following powershell command could output the "text"