Thread Dump of a python process
Peter Hansen
peter at engcorp.com
Thu Feb 9 10:04:02 EST 2006
Shanon wrote:
> I would to know if there're some way to have a dump of all the threads
> started by a python process. I want to see the TID corresponding of each
> thread because I need them to get the CPU time of each thread by the command
> top.
threading.enumerate() will return a list of all threading.Thread objects
that have been created (including the main one), but Thread's do not
currently store the identified of the underlying thread (created by a
call to thread.start_new_thread(). You could easily subclass Thread to
provide your own .start() which does that, and perhaps modify __repr__
to output that instead of the id() value.
Check the source in threading.py if this approach sounds useful.
-Peter
More information about the Python-list
mailing list