Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

does cProfile profile calls inside threads?

I ran cprofile on a bit of code, which among other things spawns several threads that do most of the work. When I looked at the output of the profiling, I see no logging of all the functions that were called inside the threads. I am sure they were called, as they do stuff that is easy to see such as writing to a DB etc.

Does cProfile not profile threads? Am I missing something?

like image 540
olamundo Avatar asked Feb 28 '23 07:02

olamundo


1 Answers

Found the answer here: link

It's worth pointing out that using the profiler only works (by default) on the main thread, and you won't get any information from other threads if you use them. This can be a bit of a gotcha as it is completely unmentioned in the profiler documentation. If you also want to profile threads, you'll want to look at the threading.setprofile() function in the docs.

like image 137
olamundo Avatar answered Mar 08 '23 12:03

olamundo