[issue29564] ResourceWarning tracking is attaching incorrect file:position to unclosed socket

Martin Panter report at bugs.python.org
Wed Feb 15 08:02:05 EST 2017


Martin Panter added the comment:

The file position is often useful when the cleanup is deterministic. Example:

def f1():
    file1 = open("/dev/null")

def f2():
    file2 = open("/dev/null")
    del file2  # ResourceWarning

f1()  # ResourceWarning at function exit
f2()

In the these cases, the line number can identify the affected code:

demo.py:8: ResourceWarning: unclosed file <_io.TextIOWrapper name='/dev/null' mode='r' encoding='UTF-8'>
  f1()  # ResourceWarning at function exit
demo.py:6: ResourceWarning: unclosed file <_io.TextIOWrapper name='/dev/null' mode='r' encoding='UTF-8'>
  del file2  # ResourceWarning

----------

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


More information about the Python-bugs-list mailing list