Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I profile a multithread program in Python?

I'm developing an inherently multithreaded module in Python, and I'd like to find out where it's spending its time. cProfile only seems to profile the main thread. Is there any way of profiling all threads involved in the calculation?

like image 782
rog Avatar asked Mar 17 '09 08:03

rog


People also ask

How do you program a multithread in Python?

Multithreading in Python You can create threads by passing a function to the Thread() constructor or by inheriting the Thread class and overriding the run() method.

How do you run a multithread function in Python?

To implement threading in Python, you have to perform three steps: Inherit the class that contains the function you want to run in a separate thread by using the Thread class. Name the function you want to execute in a thread run() . Call the start() function from the object of the class containing the run() method.

Can Python handle multithreading?

Python doesn't allow multi-threading ,but if you want to run your program speed that needs to wait for something like IO then it use a lot.

Does Python multithread automatically?

Generally, Python only uses one thread to execute the set of written statements. This means that in python only one thread will be executed at a time.


1 Answers

Please see yappi (Yet Another Python Profiler).

like image 60
sumercip Avatar answered Oct 05 '22 19:10

sumercip