Message329744
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__)
--- |
|
Date |
User |
Action |
Args |
2018-11-12 16:44:23 | vstinner | set | recipients:
+ vstinner, mgedmin, THRlWiTi, martin.panter, David Ford (FirefighterBlu3), jbakker |
2018-11-12 16:44:23 | vstinner | set | messageid: <1542041063.85.0.788709270274.issue29564@psf.upfronthosting.co.za> |
2018-11-12 16:44:23 | vstinner | link | issue29564 messages |
2018-11-12 16:44:23 | vstinner | create | |
|