gpt4 book ai didi

python - 线程垃圾回收

转载 作者:行者123 更新时间:2023-11-28 22:30:38 25 4
gpt4 key购买 nike

如果不再有任何对 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() 访问这些引用(对事件线程的引用)。

关于python - 线程垃圾回收,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42052356/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com