2017-02-05 105 views
1

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

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

我不知道任何具体的Python,但它会是很奇怪的,如果一个* running *线程突然消失。关于单线程应用程序中的主线程,你会一直参考它吗? – Holger

+1

[Python线程垃圾回收]的可能重复(http://stackoverflow.com/questions/4494832/python-threads-garbage-collection) – Xophmeister

回答

2

我相信线程模块包含线程在运行时的引用,然后在线程run()方法结束时进行清理。我不能评论模块的内部以及它如何实现这一点,但我相信这些参考(参考活动线程)可以通过访问threading.enumerate()