[issue19421] FileIO destructor imports indirectly the io module at exit

STINNER Victor report at bugs.python.org
Mon Oct 28 13:56:45 CET 2013


STINNER Victor added the comment:

By the way, the filename of the warning is not really useful. Example script test.py:
---------------------
f = open(__file__)
---------------------

At exit, Python displays:
---------------------
sys:1: ResourceWarning: unclosed file <_io.TextIOWrapper name='test.py' mode='r' encoding='UTF-8'>
---------------------

"sys" is not a real file, _Py_DisplaySourceLine() would not be able to display the Python line (the correct filename is test.py).

Python traceback when the warning is emitted, according to gdb:
---------------------
(gdb) py-bt
Traceback (most recent call first):
  <built-in method _dealloc_warn of _io.FileIO object at remote 0x7ffff1a04368>
  <built-in method _dealloc_warn of _io.BufferedReader object at remote 0x7ffff1ae4838>
  <built-in method close of _io.TextIOWrapper object at remote 0x7ffff1b97dc0>
---------------------

We are in PyImport_Cleanup(), called by Py_Finalize().

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue19421>
_______________________________________


More information about the Python-bugs-list mailing list