线程垃圾收集

时间:2017-02-05 13:01:21

标签: python multithreading garbage-collection

如果Python threading.Thread不再有任何引用但是它仍然在运行,那么它是否会被垃圾收集?

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

1 个答案:

答案 0 :(得分:4)

我相信Threading模块在线程运行时包含对线程的引用,然后在Thread run()方法完成时进行清理。我不能评论模块的内部以及它是如何实现的,但我相信这些引用(对活动线程的引用)可以通过threading.enumerate()

访问