File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -272,24 +272,27 @@ used to try to retrieve the traceback where the detroyed object was allocated.
272272
273273Example with the script ``example.py ``::
274274
275+ import warnings
276+
275277 def func():
276- f = open(__file__)
277- f = None
278+ return open(__file__)
278279
279- func()
280+ f = func()
281+ f = None
280282
281283Output of the command ``python3.6 -Wd -X tracemalloc=5 example.py ``::
282284
283- example.py:3 : ResourceWarning: unclosed file <... >
285+ example.py:7 : ResourceWarning: unclosed file <_io.TextIOWrapper name='example.py' mode='r' encoding='UTF-8' >
284286 f = None
285287 Object allocated at (most recent call first):
286- File "example.py", lineno 2
287- f = open(__file__)
288- File "example.py", lineno 5
289- func()
288+ File "example.py", lineno 4
289+ return open(__file__)
290+ File "example.py", lineno 6
291+ f = func()
290292
291293The "Object allocated at" traceback is new and only displayed if
292- :mod: `tracemalloc ` is tracing Python memory allocations.
294+ :mod: `tracemalloc ` is tracing Python memory allocations and if the
295+ :mod: `warnings ` was already imported.
293296
294297
295298zipfile
You can’t perform that action at this time.
0 commit comments