I am executing some performance tests on a messaging framework within python, and I am trying to make sure that the code is properly cleaning up after itself.
Is there a way to monitor the current number of threads owned by the process? Is there a better way to tell if I am leaking threads?
Just to make sure I clarify what I am looking for as an answer. I need a script and or program that can monitor the number of threads that a process has alive.
This function will tell you how many threads are currently alive: threading.activeCount()
. You can also enumerate those threads using the threading.enumerate()
function.
Use python profiler to generate stats files, then use gprof2dot to generate graph
gprof2dot -f pstats output.pstats | dot -Tpng -o output.png
you can use other stats viewers provided for python
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With