views:

169

answers:

3

Hey Guys,

I'm trying to dump a list of all active threads including the current stack of each. I can get a list of all threads using threading.enumerate(), but i can't figure out a way to get to the stack from there.

Background: A Zope/Plone app freaks out from time to time, consuming 100% of cpu and needs to be restarted. I have a feeling it's a loop which doesn't terminate properly, but i cannot reproduce it in the test-environemt for verification. I managed to register a signal handler which can be triggered from the outside, so i can trigger some code as soon as the situation occurs again. If I could dump the stacktrace for all active threads, that would give me a clue what goes wrong. The hole thing runs on python 2.4...

Any ideas on how to trace down situations like these are appreciated :)

Cheers, Chriss

A: 

There is an applicable recipe on ASPN. You can use threading.enumerate() to get all the tids, then just call _async_raise() with some suitable exception to force a stack trace.

jwoolard
+2  A: 

2.4. Too bad. From Python 2.5 on there is sys._current_frames().

But you could try threadframe. And if the makefile gives you trouble you could try this setup.py for threadframe

Sample output when using threadframe

jitter
+1  A: 

Use Products.signalstack; it was designed for just this purpose!

Send a USR1 signal to your Zope server and it'll immediately dump stack traces for all threads to the console. It'll do this even if all Zope threads are locked up.

Martijn Pieters
Thank you very much, this is exactly what I need!
Chriss