STINNER Victor <victor.stin...@gmail.com> added the comment:

> File descriptors opened by PyFile_FromString don't get closed
> when the reference count is decreased.

Correct, PyFile_FromString() doesn't close the file descriptor, even if you 
call its close() method. You have to call manually fclose(file->f_fp).

Or you can use PyFile_FromFile:

fp = fopen(name, mode);
if (fp == NULL) ...
obj = PyFile_FromFile(fp, name, mode, fclose);
if (obj == NULL) {
   /* no need to call fclose(fp) here, it's done by PyFile_FromFile() */
   ...
}
...
Py_DECREF(obj);

Would you like to write a patch for the documentation?

----------
nosy: +pitrou

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue14505>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to