Dump stacktraces of all active Threads

后端 未结 6 1858
离开以前
离开以前 2020-12-06 04:24

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

6条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-06 04:48

    For Python 3.3 and later, there is faulthandler.dump_traceback().

    The code below produces similar output, but includes the thread name and could be enhanced to print more information.

    for th in threading.enumerate():
        print(th)
        traceback.print_stack(sys._current_frames()[th.ident])
        print()
    

提交回复
热议问题