Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python: Performance test, ensuring cleanup

Tags:

python

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.

like image 556
Nix Avatar asked Mar 28 '11 19:03

Nix


2 Answers

This function will tell you how many threads are currently alive: threading.activeCount(). You can also enumerate those threads using the threading.enumerate() function.

like image 164
Noah Avatar answered Oct 16 '22 04:10

Noah


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

like image 34
pylover Avatar answered Oct 16 '22 04:10

pylover