转储所有活动线程的堆栈跟踪 [英] Dump stacktraces of all active Threads

查看:107
本文介绍了转储所有活动线程的堆栈跟踪的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试转储所有活动线程的列表,包括每个线程的当前堆栈.我可以使用threading.enumerate()获取所有线程的列表,但是我找不到从那里到达堆栈的方法.

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.

背景:Zope/Plone应用会不时出现异常,消耗100%的cpu并需要重新启动.我觉得这是一个循环,无法正确终止,但是我无法在test-environemt中重现该循环以进行验证.我设法注册了可以从外部触发的信号处理程序,因此一旦情况再次发生,我就可以触发一些代码.如果我可以为所有活动线程转储stacktrace,那将为我提供一个出问题的线索.漏洞在python 2.4上运行...

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 :)

干杯, 克里斯

推荐答案

使用Zope时,您要安装 mr.freeze ;这些就是为此目的而设计的!

When using Zope, you want to install Products.signalstack or mr.freeze; these were designed for just this purpose!

向您的Zope服务器发送USR1信号,它将立即将所有线程的堆栈跟踪信息转储到控制台.即使所有Zope线程都被锁定,它也会这样做.

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.

在后台,这些软件包间接使用

Under the hood these packages indirectly use threadframes; for Python versions 2.5 and up, when not using Zope, you can build the same functionality using the sys._current_frames() function to access per-thread stack frames.

Zope 2.12.5 此功能已集成到Zope本身,并且无需再安装其他软件包.

As of Zope 2.12.5 this functionality is integrated into Zope itself, and there is no need to install additional packages anymore.

这篇关于转储所有活动线程的堆栈跟踪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆