This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author brandjon
Recipients brandjon, jnoller, pitrou
Date 2012-01-23.06:38:39
SpamBayes Score 2.6574298e-12
Marked as misclassified No
Message-id <1327300721.85.0.421846539348.issue13812@psf.upfronthosting.co.za>
In-reply-to
Content
It turns out the file output was flushing due to garbage collection. When I created and held a global reference to it, it ceased to flush. Clearly, reassigning sys.stdout also held a reference to it. So it wasn't any kind of special sys.stdout-specific logic.

I tried using os.fsync to determine whether data was being saved in an OS-level buffer. But since the OS may be free to ignore fsync, it's kind of worthless for this purpose.

I also found that under Python 2.x, even a low-level exit like os._exit or multiprocessing.win32.ExitProcess, called from within a user-level function in the child, caused flushing.

My best guess is that
  1. Python 2.x is not buffering data at the Python level. I can't see how it could be and still flush it out when calling _exit().
  2. Python 3.x is buffering at the Python level, and the Python File object needs to be destroyed or explicitly flushed before the hard low-level exit() in forking.py.

The solutions I can think of for Python 3.x are:
  1. Replace "exit = win32.ExitProcess" with "exit = sys.exit". All outstanding file objects will be destroyed and flushed naturally as the interpreter is torn down.
  2. Add an explicit stdout/stderr flush where appropriate in forking.py and process.py, to ensure tracebacks get written and to match the unix behavior. Leave it to the user to worry about flushing their own streams.
  3. Continue to use win32.ExitProcess, but add some kind of mechanism for walking through all existing Python File objects and flushing/destroying them. This was a fleeting thought; it really amounts to reimplementing the behavior of destructing the Python interpreter.

I'd really like to hear if there are good reasons for why (1) isn't how it's done currently. I'd also like to hear an explanation of Python 2.x's buffering.
History
Date User Action Args
2012-01-23 06:38:41brandjonsetrecipients: + brandjon, pitrou, jnoller
2012-01-23 06:38:41brandjonsetmessageid: <1327300721.85.0.421846539348.issue13812@psf.upfronthosting.co.za>
2012-01-23 06:38:41brandjonlinkissue13812 messages
2012-01-23 06:38:40brandjoncreate