summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2016-03-19 09:33:25 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2016-03-19 09:33:25 (GMT)
commitee803a8d2ccf50e60d18ca1bb46f7a1cf3db66f5 (patch)
tree3a7f2d10fc1c9ae5bfd02bb7a16102118e9a25b5 /Doc
parent74879e41791c9c033597250476d556815921a8e3 (diff)
downloadcpython-ee803a8d2ccf50e60d18ca1bb46f7a1cf3db66f5.zip
cpython-ee803a8d2ccf50e60d18ca1bb46f7a1cf3db66f5.tar.gz
cpython-ee803a8d2ccf50e60d18ca1bb46f7a1cf3db66f5.tar.bz2
Issue #26567: enhance ResourceWarning example
Diffstat (limited to 'Doc')
-rw-r--r--Doc/whatsnew/3.6.rst21
1 files changed, 12 insertions, 9 deletions
diff --git a/Doc/whatsnew/3.6.rst b/Doc/whatsnew/3.6.rst
index b709917..1129cb3 100644
--- a/Doc/whatsnew/3.6.rst
+++ b/Doc/whatsnew/3.6.rst
@@ -272,24 +272,27 @@ used to try to retrieve the traceback where the detroyed object was allocated.
Example with the script ``example.py``::
+ import warnings
+
def func():
- f = open(__file__)
- f = None
+ return open(__file__)
- func()
+ f = func()
+ f = None
Output of the command ``python3.6 -Wd -X tracemalloc=5 example.py``::
- example.py:3: ResourceWarning: unclosed file <...>
+ example.py:7: ResourceWarning: unclosed file <_io.TextIOWrapper name='example.py' mode='r' encoding='UTF-8'>
f = None
Object allocated at (most recent call first):
- File "example.py", lineno 2
- f = open(__file__)
- File "example.py", lineno 5
- func()
+ File "example.py", lineno 4
+ return open(__file__)
+ File "example.py", lineno 6
+ f = func()
The "Object allocated at" traceback is new and only displayed if
-:mod:`tracemalloc` is tracing Python memory allocations.
+:mod:`tracemalloc` is tracing Python memory allocations and if the
+:mod:`warnings` was already imported.
zipfile