blob: b79c5f63e707d31e0be4c69f97536ae32b85f6af [file] [log] [blame]
Victor Stinnered3b0bc2013-11-23 12:27:24 +01001:mod:`tracemalloc` --- Trace memory allocations
2===============================================
3
4.. module:: tracemalloc
5 :synopsis: Trace memory allocations.
6
R David Murray6d5cb072013-12-20 14:48:50 -05007.. versionadded:: 3.4
8
Victor Stinnered3b0bc2013-11-23 12:27:24 +01009The tracemalloc module is a debug tool to trace memory blocks allocated by
10Python. It provides the following information:
11
12* Traceback where an object was allocated
13* Statistics on allocated memory blocks per filename and per line number:
14 total size, number and average size of allocated memory blocks
15* Compute the differences between two snapshots to detect memory leaks
16
17To trace most memory blocks allocated by Python, the module should be started
18as early as possible by setting the :envvar:`PYTHONTRACEMALLOC` environment
19variable to ``1``, or by using :option:`-X` ``tracemalloc`` command line
20option. The :func:`tracemalloc.start` function can be called at runtime to
21start tracing Python memory allocations.
22
23By default, a trace of an allocated memory block only stores the most recent
24frame (1 frame). To store 25 frames at startup: set the
25:envvar:`PYTHONTRACEMALLOC` environment variable to ``25``, or use the
Victor Stinner3728d6c2013-11-23 12:37:20 +010026:option:`-X` ``tracemalloc=25`` command line option.
Victor Stinnered3b0bc2013-11-23 12:27:24 +010027
Victor Stinnered3b0bc2013-11-23 12:27:24 +010028
29Examples
30========
31
32Display the top 10
33------------------
34
35Display the 10 files allocating the most memory::
36
37 import tracemalloc
38
39 tracemalloc.start()
40
41 # ... run your application ...
42
43 snapshot = tracemalloc.take_snapshot()
44 top_stats = snapshot.statistics('lineno')
45
46 print("[ Top 10 ]")
47 for stat in top_stats[:10]:
48 print(stat)
49
50
51Example of output of the Python test suite::
52
53 [ Top 10 ]
54 <frozen importlib._bootstrap>:716: size=4855 KiB, count=39328, average=126 B
55 <frozen importlib._bootstrap>:284: size=521 KiB, count=3199, average=167 B
56 /usr/lib/python3.4/collections/__init__.py:368: size=244 KiB, count=2315, average=108 B
57 /usr/lib/python3.4/unittest/case.py:381: size=185 KiB, count=779, average=243 B
58 /usr/lib/python3.4/unittest/case.py:402: size=154 KiB, count=378, average=416 B
59 /usr/lib/python3.4/abc.py:133: size=88.7 KiB, count=347, average=262 B
60 <frozen importlib._bootstrap>:1446: size=70.4 KiB, count=911, average=79 B
61 <frozen importlib._bootstrap>:1454: size=52.0 KiB, count=25, average=2131 B
62 <string>:5: size=49.7 KiB, count=148, average=344 B
63 /usr/lib/python3.4/sysconfig.py:411: size=48.0 KiB, count=1, average=48.0 KiB
64
65We can see that Python loaded ``4.8 MiB`` data (bytecode and constants) from
66modules and that the :mod:`collections` module allocated ``244 KiB`` to build
67:class:`~collections.namedtuple` types.
68
69See :meth:`Snapshot.statistics` for more options.
70
71
72Compute differences
73-------------------
74
75Take two snapshots and display the differences::
76
77 import tracemalloc
78 tracemalloc.start()
79 # ... start your application ...
80
81 snapshot1 = tracemalloc.take_snapshot()
82 # ... call the function leaking memory ...
83 snapshot2 = tracemalloc.take_snapshot()
84
85 top_stats = snapshot2.compare_to(snapshot1, 'lineno')
86
87 print("[ Top 10 differences ]")
88 for stat in top_stats[:10]:
89 print(stat)
90
91Example of output before/after running some tests of the Python test suite::
92
93 [ Top 10 differences ]
94 <frozen importlib._bootstrap>:716: size=8173 KiB (+4428 KiB), count=71332 (+39369), average=117 B
95 /usr/lib/python3.4/linecache.py:127: size=940 KiB (+940 KiB), count=8106 (+8106), average=119 B
96 /usr/lib/python3.4/unittest/case.py:571: size=298 KiB (+298 KiB), count=589 (+589), average=519 B
97 <frozen importlib._bootstrap>:284: size=1005 KiB (+166 KiB), count=7423 (+1526), average=139 B
98 /usr/lib/python3.4/mimetypes.py:217: size=112 KiB (+112 KiB), count=1334 (+1334), average=86 B
99 /usr/lib/python3.4/http/server.py:848: size=96.0 KiB (+96.0 KiB), count=1 (+1), average=96.0 KiB
100 /usr/lib/python3.4/inspect.py:1465: size=83.5 KiB (+83.5 KiB), count=109 (+109), average=784 B
101 /usr/lib/python3.4/unittest/mock.py:491: size=77.7 KiB (+77.7 KiB), count=143 (+143), average=557 B
102 /usr/lib/python3.4/urllib/parse.py:476: size=71.8 KiB (+71.8 KiB), count=969 (+969), average=76 B
103 /usr/lib/python3.4/contextlib.py:38: size=67.2 KiB (+67.2 KiB), count=126 (+126), average=546 B
104
Victor Stinner00773df2013-11-26 00:40:10 +0100105We can see that Python has loaded ``8.2 MiB`` of module data (bytecode and
106constants), and that this is ``4.4 MiB`` more than had been loaded before the
107tests, when the previous snapshot was taken. Similarly, the :mod:`linecache`
108module has cached ``940 KiB`` of Python source code to format tracebacks, all
109of it since the previous snapshot.
Victor Stinnered3b0bc2013-11-23 12:27:24 +0100110
111If the system has little free memory, snapshots can be written on disk using
112the :meth:`Snapshot.dump` method to analyze the snapshot offline. Then use the
113:meth:`Snapshot.load` method reload the snapshot.
114
115
116Get the traceback of a memory block
117-----------------------------------
118
119Code to display the traceback of the biggest memory block::
120
Victor Stinnered3b0bc2013-11-23 12:27:24 +0100121 import tracemalloc
122
Victor Stinner3728d6c2013-11-23 12:37:20 +0100123 # Store 25 frames
124 tracemalloc.start(25)
Victor Stinnered3b0bc2013-11-23 12:27:24 +0100125
126 # ... run your application ...
127
128 snapshot = tracemalloc.take_snapshot()
129 top_stats = snapshot.statistics('traceback')
130
131 # pick the biggest memory block
132 stat = top_stats[0]
133 print("%s memory blocks: %.1f KiB" % (stat.count, stat.size / 1024))
Victor Stinner23f628d2014-02-16 23:53:38 +0100134 for line in stat.traceback.format():
135 print(line)
Victor Stinnered3b0bc2013-11-23 12:27:24 +0100136
137Example of output of the Python test suite (traceback limited to 25 frames)::
138
139 903 memory blocks: 870.1 KiB
140 File "<frozen importlib._bootstrap>", line 716
141 File "<frozen importlib._bootstrap>", line 1036
142 File "<frozen importlib._bootstrap>", line 934
143 File "<frozen importlib._bootstrap>", line 1068
144 File "<frozen importlib._bootstrap>", line 619
145 File "<frozen importlib._bootstrap>", line 1581
146 File "<frozen importlib._bootstrap>", line 1614
147 File "/usr/lib/python3.4/doctest.py", line 101
148 import pdb
149 File "<frozen importlib._bootstrap>", line 284
150 File "<frozen importlib._bootstrap>", line 938
151 File "<frozen importlib._bootstrap>", line 1068
152 File "<frozen importlib._bootstrap>", line 619
153 File "<frozen importlib._bootstrap>", line 1581
154 File "<frozen importlib._bootstrap>", line 1614
155 File "/usr/lib/python3.4/test/support/__init__.py", line 1728
156 import doctest
157 File "/usr/lib/python3.4/test/test_pickletools.py", line 21
158 support.run_doctest(pickletools)
159 File "/usr/lib/python3.4/test/regrtest.py", line 1276
160 test_runner()
161 File "/usr/lib/python3.4/test/regrtest.py", line 976
162 display_failure=not verbose)
163 File "/usr/lib/python3.4/test/regrtest.py", line 761
164 match_tests=ns.match_tests)
165 File "/usr/lib/python3.4/test/regrtest.py", line 1563
166 main()
167 File "/usr/lib/python3.4/test/__main__.py", line 3
168 regrtest.main_in_temp_cwd()
169 File "/usr/lib/python3.4/runpy.py", line 73
170 exec(code, run_globals)
171 File "/usr/lib/python3.4/runpy.py", line 160
172 "__main__", fname, loader, pkg_name)
173
Victor Stinner00773df2013-11-26 00:40:10 +0100174We can see that the most memory was allocated in the :mod:`importlib` module to
Victor Stinnered3b0bc2013-11-23 12:27:24 +0100175load data (bytecode and constants) from modules: ``870 KiB``. The traceback is
Victor Stinner00773df2013-11-26 00:40:10 +0100176where the :mod:`importlib` loaded data most recently: on the ``import pdb``
177line of the :mod:`doctest` module. The traceback may change if a new module is
178loaded.
Victor Stinnered3b0bc2013-11-23 12:27:24 +0100179
180
181Pretty top
182----------
183
184Code to display the 10 lines allocating the most memory with a pretty output,
185ignoring ``<frozen importlib._bootstrap>`` and ``<unknown>`` files::
186
187 import os
188 import tracemalloc
189
190 def display_top(snapshot, group_by='lineno', limit=10):
191 snapshot = snapshot.filter_traces((
192 tracemalloc.Filter(False, "<frozen importlib._bootstrap>"),
193 tracemalloc.Filter(False, "<unknown>"),
194 ))
195 top_stats = snapshot.statistics(group_by)
196
197 print("Top %s lines" % limit)
198 for index, stat in enumerate(top_stats[:limit], 1):
199 frame = stat.traceback[0]
200 # replace "/path/to/module/file.py" with "module/file.py"
201 filename = os.sep.join(frame.filename.split(os.sep)[-2:])
202 print("#%s: %s:%s: %.1f KiB"
203 % (index, filename, frame.lineno,
204 stat.size / 1024))
205
206 other = top_stats[limit:]
207 if other:
208 size = sum(stat.size for stat in other)
209 print("%s other: %.1f KiB" % (len(other), size / 1024))
210 total = sum(stat.size for stat in top_stats)
211 print("Total allocated size: %.1f KiB" % (total / 1024))
212
213 tracemalloc.start()
214
215 # ... run your application ...
216
217 snapshot = tracemalloc.take_snapshot()
218 display_top(snapshot, 10)
219
220Example of output of the Python test suite::
221
222 2013-11-08 14:16:58.149320: Top 10 lines
223 #1: collections/__init__.py:368: 291.9 KiB
224 #2: Lib/doctest.py:1291: 200.2 KiB
225 #3: unittest/case.py:571: 160.3 KiB
226 #4: Lib/abc.py:133: 99.8 KiB
227 #5: urllib/parse.py:476: 71.8 KiB
228 #6: <string>:5: 62.7 KiB
229 #7: Lib/base64.py:140: 59.8 KiB
230 #8: Lib/_weakrefset.py:37: 51.8 KiB
231 #9: collections/__init__.py:362: 50.6 KiB
232 #10: test/test_site.py:56: 48.0 KiB
233 7496 other: 4161.9 KiB
234 Total allocated size: 5258.8 KiB
235
236See :meth:`Snapshot.statistics` for more options.
237
238
239API
240===
241
242Functions
243---------
244
245.. function:: clear_traces()
246
247 Clear traces of memory blocks allocated by Python.
248
249 See also :func:`stop`.
250
251
252.. function:: get_object_traceback(obj)
253
254 Get the traceback where the Python object *obj* was allocated.
255 Return a :class:`Traceback` instance, or ``None`` if the :mod:`tracemalloc`
256 module is not tracing memory allocations or did not trace the allocation of
257 the object.
258
259 See also :func:`gc.get_referrers` and :func:`sys.getsizeof` functions.
260
261
262.. function:: get_traceback_limit()
263
264 Get the maximum number of frames stored in the traceback of a trace.
265
Victor Stinner3728d6c2013-11-23 12:37:20 +0100266 The :mod:`tracemalloc` module must be tracing memory allocations to
267 get the limit, otherwise an exception is raised.
Victor Stinnered3b0bc2013-11-23 12:27:24 +0100268
Victor Stinner3728d6c2013-11-23 12:37:20 +0100269 The limit is set by the :func:`start` function.
Victor Stinnered3b0bc2013-11-23 12:27:24 +0100270
271
272.. function:: get_traced_memory()
273
Victor Stinner3c0481d2013-11-27 21:39:49 +0100274 Get the current size and peak size of memory blocks traced by the
275 :mod:`tracemalloc` module as a tuple: ``(current: int, peak: int)``.
Victor Stinnered3b0bc2013-11-23 12:27:24 +0100276
277
278.. function:: get_tracemalloc_memory()
279
280 Get the memory usage in bytes of the :mod:`tracemalloc` module used to store
281 traces of memory blocks.
282 Return an :class:`int`.
283
284
285.. function:: is_tracing()
286
287 ``True`` if the :mod:`tracemalloc` module is tracing Python memory
288 allocations, ``False`` otherwise.
289
290 See also :func:`start` and :func:`stop` functions.
291
292
Victor Stinner3728d6c2013-11-23 12:37:20 +0100293.. function:: start(nframe: int=1)
Victor Stinnered3b0bc2013-11-23 12:27:24 +0100294
Victor Stinner3728d6c2013-11-23 12:37:20 +0100295 Start tracing Python memory allocations: install hooks on Python memory
296 allocators. Collected tracebacks of traces will be limited to *nframe*
297 frames. By default, a trace of a memory block only stores the most recent
298 frame: the limit is ``1``. *nframe* must be greater or equal to ``1``.
Victor Stinnered3b0bc2013-11-23 12:27:24 +0100299
300 Storing more than ``1`` frame is only useful to compute statistics grouped
301 by ``'traceback'`` or to compute cumulative statistics: see the
302 :meth:`Snapshot.compare_to` and :meth:`Snapshot.statistics` methods.
303
304 Storing more frames increases the memory and CPU overhead of the
305 :mod:`tracemalloc` module. Use the :func:`get_tracemalloc_memory` function
306 to measure how much memory is used by the :mod:`tracemalloc` module.
307
308 The :envvar:`PYTHONTRACEMALLOC` environment variable
309 (``PYTHONTRACEMALLOC=NFRAME``) and the :option:`-X` ``tracemalloc=NFRAME``
Victor Stinner3728d6c2013-11-23 12:37:20 +0100310 command line option can be used to start tracing at startup.
Victor Stinnered3b0bc2013-11-23 12:27:24 +0100311
Victor Stinner3728d6c2013-11-23 12:37:20 +0100312 See also :func:`stop`, :func:`is_tracing` and :func:`get_traceback_limit`
313 functions.
Victor Stinnered3b0bc2013-11-23 12:27:24 +0100314
315
316.. function:: stop()
317
318 Stop tracing Python memory allocations: uninstall hooks on Python memory
Victor Stinner00773df2013-11-26 00:40:10 +0100319 allocators. Also clears all previously collected traces of memory blocks
320 allocated by Python.
Victor Stinnered3b0bc2013-11-23 12:27:24 +0100321
322 Call :func:`take_snapshot` function to take a snapshot of traces before
323 clearing them.
324
Victor Stinner00773df2013-11-26 00:40:10 +0100325 See also :func:`start`, :func:`is_tracing` and :func:`clear_traces`
326 functions.
Victor Stinnered3b0bc2013-11-23 12:27:24 +0100327
328
329.. function:: take_snapshot()
330
331 Take a snapshot of traces of memory blocks allocated by Python. Return a new
332 :class:`Snapshot` instance.
333
334 The snapshot does not include memory blocks allocated before the
335 :mod:`tracemalloc` module started to trace memory allocations.
336
337 Tracebacks of traces are limited to :func:`get_traceback_limit` frames. Use
Victor Stinner3728d6c2013-11-23 12:37:20 +0100338 the *nframe* parameter of the :func:`start` function to store more frames.
Victor Stinnered3b0bc2013-11-23 12:27:24 +0100339
340 The :mod:`tracemalloc` module must be tracing memory allocations to take a
341 snapshot, see the the :func:`start` function.
342
343 See also the :func:`get_object_traceback` function.
344
345
346Filter
347------
348
349.. class:: Filter(inclusive: bool, filename_pattern: str, lineno: int=None, all_frames: bool=False)
350
351 Filter on traces of memory blocks.
352
353 See the :func:`fnmatch.fnmatch` function for the syntax of
354 *filename_pattern*. The ``'.pyc'`` and ``'.pyo'`` file extensions are
355 replaced with ``'.py'``.
356
357 Examples:
358
359 * ``Filter(True, subprocess.__file__)`` only includes traces of the
360 :mod:`subprocess` module
361 * ``Filter(False, tracemalloc.__file__)`` excludes traces of the
362 :mod:`tracemalloc` module
363 * ``Filter(False, "<unknown>")`` excludes empty tracebacks
364
365 .. attribute:: inclusive
366
367 If *inclusive* is ``True`` (include), only trace memory blocks allocated
368 in a file with a name matching :attr:`filename_pattern` at line number
369 :attr:`lineno`.
370
371 If *inclusive* is ``False`` (exclude), ignore memory blocks allocated in
372 a file with a name matching :attr:`filename_pattern` at line number
373 :attr:`lineno`.
374
375 .. attribute:: lineno
376
377 Line number (``int``) of the filter. If *lineno* is ``None``, the filter
378 matches any line number.
379
380 .. attribute:: filename_pattern
381
382 Filename pattern of the filter (``str``).
383
384 .. attribute:: all_frames
385
386 If *all_frames* is ``True``, all frames of the traceback are checked. If
387 *all_frames* is ``False``, only the most recent frame is checked.
388
Victor Stinner5362abf2013-11-27 23:39:55 +0100389 This attribute has no effect if the traceback limit is ``1``. See the
390 :func:`get_traceback_limit` function and :attr:`Snapshot.traceback_limit`
391 attribute.
Victor Stinnered3b0bc2013-11-23 12:27:24 +0100392
393
394Frame
395-----
396
397.. class:: Frame
398
399 Frame of a traceback.
400
401 The :class:`Traceback` class is a sequence of :class:`Frame` instances.
402
403 .. attribute:: filename
404
405 Filename (``str``).
406
407 .. attribute:: lineno
408
409 Line number (``int``).
410
411
412Snapshot
413--------
414
415.. class:: Snapshot
416
417 Snapshot of traces of memory blocks allocated by Python.
418
419 The :func:`take_snapshot` function creates a snapshot instance.
420
421 .. method:: compare_to(old_snapshot: Snapshot, group_by: str, cumulative: bool=False)
422
423 Compute the differences with an old snapshot. Get statistics as a sorted
424 list of :class:`StatisticDiff` instances grouped by *group_by*.
425
426 See the :meth:`statistics` method for *group_by* and *cumulative*
427 parameters.
428
429 The result is sorted from the biggest to the smallest by: absolute value
430 of :attr:`StatisticDiff.size_diff`, :attr:`StatisticDiff.size`, absolute
431 value of :attr:`StatisticDiff.count_diff`, :attr:`Statistic.count` and
432 then by :attr:`StatisticDiff.traceback`.
433
434
435 .. method:: dump(filename)
436
437 Write the snapshot into a file.
438
439 Use :meth:`load` to reload the snapshot.
440
441
442 .. method:: filter_traces(filters)
443
444 Create a new :class:`Snapshot` instance with a filtered :attr:`traces`
445 sequence, *filters* is a list of :class:`Filter` instances. If *filters*
446 is an empty list, return a new :class:`Snapshot` instance with a copy of
447 the traces.
448
449 All inclusive filters are applied at once, a trace is ignored if no
450 inclusive filters match it. A trace is ignored if at least one exclusive
451 filter matchs it.
452
453
454 .. classmethod:: load(filename)
455
456 Load a snapshot from a file.
457
458 See also :meth:`dump`.
459
460
461 .. method:: statistics(group_by: str, cumulative: bool=False)
462
463 Get statistics as a sorted list of :class:`Statistic` instances grouped
464 by *group_by*:
465
466 ===================== ========================
467 group_by description
468 ===================== ========================
469 ``'filename'`` filename
470 ``'lineno'`` filename and line number
471 ``'traceback'`` traceback
472 ===================== ========================
473
474 If *cumulative* is ``True``, cumulate size and count of memory blocks of
475 all frames of the traceback of a trace, not only the most recent frame.
476 The cumulative mode can only be used with *group_by* equals to
Victor Stinner8e3708d2013-11-26 00:45:47 +0100477 ``'filename'`` and ``'lineno'``.
Victor Stinnered3b0bc2013-11-23 12:27:24 +0100478
479 The result is sorted from the biggest to the smallest by:
480 :attr:`Statistic.size`, :attr:`Statistic.count` and then by
481 :attr:`Statistic.traceback`.
482
483
484 .. attribute:: traceback_limit
485
486 Maximum number of frames stored in the traceback of :attr:`traces`:
487 result of the :func:`get_traceback_limit` when the snapshot was taken.
488
489 .. attribute:: traces
490
491 Traces of all memory blocks allocated by Python: sequence of
492 :class:`Trace` instances.
493
494 The sequence has an undefined order. Use the :meth:`Snapshot.statistics`
495 method to get a sorted list of statistics.
496
497
498Statistic
499---------
500
501.. class:: Statistic
502
503 Statistic on memory allocations.
504
505 :func:`Snapshot.statistics` returns a list of :class:`Statistic` instances.
506
507 See also the :class:`StatisticDiff` class.
508
509 .. attribute:: count
510
511 Number of memory blocks (``int``).
512
513 .. attribute:: size
514
515 Total size of memory blocks in bytes (``int``).
516
517 .. attribute:: traceback
518
519 Traceback where the memory block was allocated, :class:`Traceback`
520 instance.
521
522
523StatisticDiff
524-------------
525
526.. class:: StatisticDiff
527
528 Statistic difference on memory allocations between an old and a new
529 :class:`Snapshot` instance.
530
531 :func:`Snapshot.compare_to` returns a list of :class:`StatisticDiff`
532 instances. See also the :class:`Statistic` class.
533
534 .. attribute:: count
535
536 Number of memory blocks in the new snapshot (``int``): ``0`` if
537 the memory blocks have been released in the new snapshot.
538
539 .. attribute:: count_diff
540
541 Difference of number of memory blocks between the old and the new
542 snapshots (``int``): ``0`` if the memory blocks have been allocated in
543 the new snapshot.
544
545 .. attribute:: size
546
547 Total size of memory blocks in bytes in the new snapshot (``int``):
548 ``0`` if the memory blocks have been released in the new snapshot.
549
550 .. attribute:: size_diff
551
552 Difference of total size of memory blocks in bytes between the old and
553 the new snapshots (``int``): ``0`` if the memory blocks have been
554 allocated in the new snapshot.
555
556 .. attribute:: traceback
557
558 Traceback where the memory blocks were allocated, :class:`Traceback`
559 instance.
560
561
562Trace
563-----
564
565.. class:: Trace
566
567 Trace of a memory block.
568
569 The :attr:`Snapshot.traces` attribute is a sequence of :class:`Trace`
570 instances.
571
572 .. attribute:: size
573
574 Size of the memory block in bytes (``int``).
575
576 .. attribute:: traceback
577
578 Traceback where the memory block was allocated, :class:`Traceback`
579 instance.
580
581
582Traceback
583---------
584
585.. class:: Traceback
586
587 Sequence of :class:`Frame` instances sorted from the most recent frame to
588 the oldest frame.
589
590 A traceback contains at least ``1`` frame. If the ``tracemalloc`` module
591 failed to get a frame, the filename ``"<unknown>"`` at line number ``0`` is
592 used.
593
594 When a snapshot is taken, tracebacks of traces are limited to
595 :func:`get_traceback_limit` frames. See the :func:`take_snapshot` function.
596
597 The :attr:`Trace.traceback` attribute is an instance of :class:`Traceback`
598 instance.
599
Victor Stinner23f628d2014-02-16 23:53:38 +0100600 .. method:: format(limit=None)
601
602 Format the traceback as a list of lines with newlines. Use the
603 :mod:`linecache` module to retrieve lines from the source code. If
604 *limit* is set, only format the *limit* most recent frames.
605
606 Similar to the :func:`traceback.format_tb` function, except that
607 :meth:`format` does not include newlines.
608
609 Example::
610
611 print("Traceback (most recent call first):")
612 for line in traceback:
613 print(line)
614
615 Output::
616
617 Traceback (most recent call first):
618 File "test.py", line 9
619 obj = Object()
620 File "test.py", line 12
621 tb = tracemalloc.get_object_traceback(f())
Victor Stinnered3b0bc2013-11-23 12:27:24 +0100622