【问题标题】:Thread garbage collection线程垃圾回收
【发布时间】:2017-02-05 13:01:20
【问题描述】:

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

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

【问题讨论】:

  • 我对Python一无所知,但是如果一个running线程突然消失就很奇怪了。单线程应用中的主线程呢,你是不是一直保持着对它的引用呢?

标签: python multithreading garbage-collection


【解决方案1】:

我相信 Threading 模块在运行时包含对线程的引用,然后在 Thread run() 方法完成时被清除。我无法评论模块的内部结构以及它是如何实现这一点的,但我相信这些引用(对活动线程的引用)可以通过threading.enumerate()

访问

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-21
    • 2012-01-28
    相关资源
    最近更新 更多