STINNER Victor <vstin...@redhat.com> added the comment:

Example:
---
import warnings
import tracemalloc

#tracemalloc.start(5)

# always log ResourceWarning messages
warnings.simplefilter("always", ResourceWarning)
def func():
    f = open(__file__)
    # emit ResourceWarning
    f = None
func()
---

Output with Python 3.7:
---
$ python3 script.py
script.py:11: ResourceWarning: unclosed file <_io.TextIOWrapper 
name='script.py' mode='r' encoding='UTF-8'>
  f = None
---

Output with my attached PR 10486:
---
$ python3 script.py
script.py:11: ResourceWarning: unclosed file <_io.TextIOWrapper 
name='script.py' mode='r' encoding='UTF-8'>
  f = None
ResourceWarning: Enable tracemalloc to get the object allocation traceback
---

Finally, if tracemalloc is enabled:
---
$ ./python -X tracemalloc=5 script.py 
script.py:11: ResourceWarning: unclosed file <_io.TextIOWrapper 
name='script.py' mode='r' encoding='UTF-8'>
  f = None
Object allocated at (most recent call last):
  File "script.py", lineno 12
    func()
  File "script.py", lineno 9
    f = open(__file__)
---

----------
resolution: not a bug -> 

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

Reply via email to