如果不再引用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
我认为 Threading 模块在线程运行时包含了对线程的引用,并且在 Thread 的 run() 方法执行完后被清除。我无法对模块的内部和实现方式发表评论,但我相信可以通过 threading.enumerate() 访问这些引用(活动线程的引用)。