Author vstinner
Recipients David Ford (FirefighterBlu3), THRlWiTi, jbakker, martin.panter, mgedmin, vstinner
Date 2018-11-12.16:44:23
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1542041063.85.0.788709270274.issue29564@psf.upfronthosting.co.za>
In-reply-to
Content
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__)
---
History
Date User Action Args
2018-11-12 16:44:23vstinnersetrecipients: + vstinner, mgedmin, THRlWiTi, martin.panter, David Ford (FirefighterBlu3), jbakker
2018-11-12 16:44:23vstinnersetmessageid: <1542041063.85.0.788709270274.issue29564@psf.upfronthosting.co.za>
2018-11-12 16:44:23vstinnerlinkissue29564 messages
2018-11-12 16:44:23vstinnercreate