When using configparser read method, the file(s) remains opened and cannot be closed, causing ResourceWarning: unclosed file. For example in the following code: config = configparser.ConfigParser() config.read(cfg_fn) ... the file cfg_fn remains opened and is only closed upon destruction of the underlying file object. At some point in history the method read used to close the file, but this has been changed for some reason.
I am sorry, I can only reproduce it in the production environment so far, it does only occur on Ubuntu Linux (Python 3.5.1) and I am developing on Windows. So right now I cannot narrow it down (it does not occur with simple code, unfortunately). This is what I get after some experimentation: Exception ignored in: <_io.FileIO name='config.ini' mode='rb' closefd=True> ResourceWarning: unclosed file <_io.TextIOWrapper name='config.ini' mode='r' encoding='UTF-8'> The only place when I work with config.ini is the read method of ConfigParser, so it definitely should be an issue in ConfigParser.
Thanks for your comments, I am myself quite puzzled how is it possible that the file is not closed after having been read. I suspect this to be an OS problem, therefore I am closing the bug for now.
History
Date
User
Action
Args
2022-04-11 14:58:39
admin
set
github: 72818
2016-11-13 13:15:11
SilentGhost
set
stage: resolved
2016-11-13 11:59:11
PetrPy
set
status: open -> closedresolution: not a bugmessages: +