[Python-Dev] PEP 454 (tracemalloc) disable ==> clear?

Victor Stinner victor.stinner at gmail.com
Tue Oct 29 12:37:52 CET 2013


2013/10/29 Jim Jewett <jimjjewett at gmail.com>:
>     reset() function:
>
>         Clear traces of memory blocks allocated by Python.
>
> Does this do anything besides clear?  If not, why not just re-use the
> 'clear' name from dicts?

(I like the reset() name. Charles-François suggested this name
inspired by OProfile API.)

>     disable() function:
>
>         Stop tracing Python memory allocations and clear traces of
>         memory blocks allocated by Python.
>
> I would disable to stop tracing, but I would not expect it to clear
> out the traces it had already captured.  If it has to do that, please
> put in some sample code showing how to save the current traces before
> disabling.

For consistency, you cannot keep traces when tracing is disabled. The
free() must be enabled to remove allocated memory blocks, or next
malloc() may get the same address which would raise an assertion error
(you cannot have two memory blocks at the same address).

Just call get_traces() to get traces before clearing them. I can
explain it in the doc.

2013/10/29 Kristján Valur Jónsson <kristjan at ccpgames.com>:
> I was thinking something similar.  It would be useful to be able to "pause" and "resume"
> if one is doing any analysis work in the live environment.  This would reduce the
> need to have "Filter" objects.

For the reason explained above, it's not possible to disable the whole
module temporarly.

Internally, tracemalloc uses a thread-local variable (called the
"reentrant" flag) to disable temporarly tracing allocations in the
current thread. It only disables tracing new allocations,
deallocations are still proceed.

Victor


More information about the Python-Dev mailing list