[英]What happens to thread started in the class instance when all references to the instance are destroyed (Python)?
問題在標題中。
代碼示例:
class A:
def start_thread(self):
t1 = threading.Thread(target=something)
t1.start()
a = A()
a.start_thread()
a = A()
那么,我們開始的線程會發生什么?
threading
模塊本身保留對每個活動Thread
對象的引用,因此即使引用消失,正在運行的線程也將繼續運行。
線程保存在 Python 運行時的單獨注冊表中,您可以通過調用threading.enumerate
( https://docs.python.org/3/library/threading.html#threading.enumerate ) 來“查看”它們 - 這是沒有什么不同,然后不保留對以任何其他方式啟動的線程的引用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.