Python 线程:“sys._current_frames()”与“threading.enumerate()”相比
我有一个程序可以分叉许多子进程(为此,它使用了 Celery Workers)。我正在尝试转储每个进程中所有正在运行的线程的堆栈跟踪。我使用 sys._current_frames() 来获取堆栈跟踪,并使用 threading.enumerate() 来获取线程名称。
出于某种原因,我注意到,在我的分叉子进程中,我有比实际线程更多的“框架”。这是正常的吗?这些只是叉子上的“剩菜”吗?这是Python 中的一个错误吗? (在 Mac OS X 上测试,以供记录)
谢谢, Z
I have a program which forks a number of subprocesses (it's using Celery Workers for that matter). I'm trying to dump the stack traces of all the running threads in each process. I'm using sys._current_frames()
to get the stack traces and threading.enumerate()
to get the thread names.
For some reason, I noticed that, in my forked sub-processes, I have more "frames" than actual threads. Is this normal? Are these just "leftovers" from the fork? Is it a bug in Python? (tested on Mac OS X, for the record)
Thanks,
Z
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是错误 17094。它应该在以后的 Python 版本中得到修复。
This is bug 17094. It should be fixed in later Python versions.
那么 sys._current_frames 的文档稍微解释了一些事情
首先
所以这并不是你真正应该戳的东西。关键答案来自 threading.enumerate 文档
Well the documentation of sys._current_frames explains something slightly
Firstly
So its not really something you should be poking. And the key answer comes from threading.enumerate documentation