Current execution frame of another thread?

Diez B. Roggisch deets at
Thu Nov 17 19:33:16 CET 2005

skip at wrote:
> I would like to try a sampling approach to profiling.  My thought is to have
> a profiling thread that samples the execution frame of all the other
> started threads.  I don't see any path from the threads returned by
> threading.enumerate() to their current frames.  Am I missing something?

I doubt that works. As python uses the OS underlying threading model, it 
doesnn't know about the internal management structures - and even it 
knew, these had to be carefully designed for that exact purposes of 
yours, as the stack frame can only be safely inspected by the thread 
_running_ in it.

An external thread could be interrupted at all times while traversing 
other threads management structures, and then find a corrupted memory 
location when it is re-scheduled.

Maybe one could write a threading model that allwos for hooks in the 
scheduler (which has all the time in the world for such stuff) - but I'm 
not aware that that's possible under e.g. pthreads, so there is unlikely 
a python-way to do so.



More information about the Python-list mailing list