Python 线程:“sys._current_frames()”与“threading.enumerate()”相比

发布于 2024-12-15 08:50:15 字数 262 浏览 2 评论 0原文

我有一个程序可以分叉许多子进程(为此,它使用了 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

宣告ˉ结束 2024-12-22 08:50:15

这是错误 17094。它应该在以后的 Python 版本中得到修复。

This is bug 17094. It should be fixed in later Python versions.

那么 sys._current_frames 的文档稍微解释了一些事情
首先

此函数只能用于内部和专门目的。

所以这并不是你真正应该戳的东西。关键答案来自 t​​hreading.enumerate 文档

该列表包括守护线程、由 current_thread() 创建的虚拟线程对象和主线程。

Well the documentation of sys._current_frames explains something slightly
Firstly

This function should be used for internal and specialized purposes only.

So its not really something you should be poking. And the key answer comes from threading.enumerate documentation

The list includes daemonic threads, dummy thread objects created by current_thread(), and the main thread.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文