[issue4233] open(0, closefd=False) prints 3 warnings
Christian Heimes
report at bugs.python.org
Fri Oct 31 22:37:42 CET 2008
Christian Heimes <lists at cheimes.de> added the comment:
I don't see a good 'n easy way to fix the issue. close() is called in
too many places and I don't wanna add more checks in Python code.
This patch reduces the mass of warnings to one, but it also changes the
semantic of close() a bit. However it seems logical to set the fd
attribute of the file object to -1 (meaning closed).
Index: Modules/_fileio.c
===================================================================
--- Modules/_fileio.c (Revision 67068)
+++ Modules/_fileio.c (Arbeitskopie)
@@ -60,7 +60,8 @@
static PyObject *
fileio_close(PyFileIOObject *self)
{
- if (!self->closefd) {
+ if (!self->closefd && self->fd >= 0) {
+ self->fd = -1;
if (PyErr_WarnEx(PyExc_RuntimeWarning,
"Trying to close unclosable fd!", 3) < 0) {
return NULL;
----------
nosy: +christian.heimes
priority: critical -> release blocker
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue4233>
_______________________________________
More information about the Python-bugs-list
mailing list