1
Python threading.Thread
是否會被垃圾回收,如果不再有任何引用,但它仍在運行?線程垃圾回收
# Start a thread with no reference
Thread(target=some_long_running_function).start()
# Do lots of other stuff
Python threading.Thread
是否會被垃圾回收,如果不再有任何引用,但它仍在運行?線程垃圾回收
# Start a thread with no reference
Thread(target=some_long_running_function).start()
# Do lots of other stuff
我相信線程模塊包含線程在運行時的引用,然後在線程run()方法結束時進行清理。我不能評論模塊的內部以及它如何實現這一點,但我相信這些參考(參考活動線程)可以通過訪問threading.enumerate()
我不知道任何具體的Python,但它會是很奇怪的,如果一個* running *線程突然消失。關於單線程應用程序中的主線程,你會一直參考它嗎? – Holger
[Python線程垃圾回收]的可能重複(http://stackoverflow.com/questions/4494832/python-threads-garbage-collection) – Xophmeister