![](https://secure.gravatar.com/avatar/daa45563a98419bb1b6b63904ce71f95.jpg?s=120&d=mm&r=g)
2013/10/29 Victor Stinner <victor.stinner@gmail.com>:
2013/10/29 Kristján Valur Jónsson <kristjan@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