简体   繁体   中英

Python threading: “sys._current_frames()” vs “threading.enumerate()”

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

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM