Speeding up Python's exit

Ross Ridge rridge at csclub.uwaterloo.ca
Mon Mar 4 00:27:08 CET 2013


Antoine Pitrou  <solipsis at pitrou.net> wrote:
>Now please read my message again. The OS buffers are *not* flushed according
>to POSIX.

POSIX says open *streams* might not be flushed.  POSIX streams are C
FILE * streams and generally aren't regarded as being part of the OS.

When you call os._exit() in a Python program any unwritten data still
in Python's own file buffers will be lost.  Any unwritten data still
in the C library's FILE * buffers will be lost.  Any data successfuly
written through a POSIX file descriptor (eg. using the write() function)
will not be lost becasue os._exit() was used.

Note that this doesn't mean that OS buffers will flushed when os._exit()
is called.  Data that hasn't yet been physically written to disk, hasn't
be successfully transmitted over the network, or otherwise hasn't been
fully comitted could still be lost.  However, exiting Python normally
doesn't change this.  Only the Python process's own internal buffers are
flushed, the OS doesn't change its handling of its buffers.  If you want
written data to be fully committed before exiting you need to use other
OS services that guarantee this.

					Ross Ridge

-- 
 l/  //	  Ross Ridge -- The Great HTMU
[oo][oo]  rridge at csclub.uwaterloo.ca
-()-/()/  http://www.csclub.uwaterloo.ca/~rridge/ 
 db  //	  



More information about the Python-list mailing list