线程垃圾收集

Xop*_*ter 7 python multithreading garbage-collection

threading.Thread如果不再有任何对Python 的引用但它仍在运行,它会被垃圾收集吗?

# Start a thread with no reference
Thread(target=some_long_running_function).start()
# Do lots of other stuff
Run Code Online (Sandbox Code Playgroud)

Sig*_*ide 6

我相信 Threading 模块在线程运行时包含对线程的引用,然后在 Thread run() 方法完成时被清除。我无法评论模块的内部结构以及它如何实现这一点,但我相信这些引用(对活动线程的引用)可以通过threading.enumerate()访问