IOError on file close

Martin v. Loewis martin at v.loewis.de
Fri Mar 29 18:11:37 EST 2002


"Michael S. Fischer" <michael+usenet at dynamine.net> writes:

> It appears that the write() call is the one that's failing, not the
> close() call.  Python is throwing the exception at the wrong time. 
> Should I report this as a Python bug?

Not really. My guess is that the C library buffers the write call, and
attempts to flush the stream when closing the file. This, in turn,
produces the error - the write itself succeeds. Python uses the code

	n2 = fwrite(s, 1, n, f->f_fp);
	if (n2 != n) {
		PyErr_SetFromErrno(PyExc_IOError);
		clearerr(f->f_fp);
		return NULL;
	}

so it would definitely report an exception if fwrite reported an error.

Just try opening the file without buffering.

Regards,
Martin
 



More information about the Python-list mailing list