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

Victor Stinner victor.stinner at gmail.com
Thu Oct 31 11:41:20 CET 2013


2013/10/29 Victor Stinner <victor.stinner at gmail.com>:
> 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.
>
> 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.

If I give access to this flag, it would be possible to disable
temporarily tracing in the current thread, but tracing would still be
enabled in other threads. Would it fit your requirement?

Example:
---------------
tracemalloc.enable()
# start your application
...
# spawn many threads
...
# oh no, I don't want to trace this ugly function
tracemalloc.disable_local()
ugly_function()
tracemalloc.enable_local()
...
snapshot = take_snapshot()
---------------

You can imagine a context manager based on these two functions:
---------------
with disable_tracing_temporarily_in_current_thread():
  ugly_function()
---------------

I still don't understand why you would need to stop tracing
temporarily. When I use tracemalloc, I never disable it.

Victor


More information about the Python-Dev mailing list