Index: Objects/fileobject.c =================================================================== --- Objects/fileobject.c (revision 82910) +++ Objects/fileobject.c (working copy) @@ -360,10 +360,6 @@ } return NULL; } - /* NULL out the FILE pointer before releasing the GIL, because - * it will not be valid anymore after the close() function is - * called. */ - f->f_fp = NULL; if (local_close != NULL) { Py_BEGIN_ALLOW_THREADS errno = 0; @@ -569,6 +565,7 @@ { PyObject *sts = close_the_file(f); if (sts) { + f->f_fp = NULL; PyMem_Free(f->f_setbuf); f->f_setbuf = NULL; }