线程垃圾回收 [英] Thread garbage collection

查看:163
本文介绍了线程垃圾回收的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果不再有Python threading.Thread引用,但它仍在运行,是否会对其进行垃圾回收?

Will a Python threading.Thread ever be garbage collected if there is no longer any reference to it but it's still running?

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

推荐答案

我相信Threading模块在运行时包含对线程的引用,然后在Thread run()方法完成后将其清除.我无法评论模块的内部及其如何实现此功能,但是我相信可以通过

I believe the Threading module contains a reference to the thread whilst it is running and is then cleaned when the Thread run() method has finished. I cannot comment on the internals of the module and how it accomplishes this but I believe these references (references to active threads) can be accessed via threading.enumerate()

这篇关于线程垃圾回收的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆