问题描述
如果我在Python(3.6+)中创建了一个守护线程,并且该守护线程已完成执行,它的资源是否会自动释放,还是发生内存泄漏?我环顾四周找不到真正的答案...我以为它已被释放,但偏执狂并希望有人能澄清。
我举了一个基本的例子:
import threading
import time
class Processor():
def get_data_in_thread(self,id):
for i in range(3):
time.sleep(1)
print(f'{id} count: {i}')
#at this point is this thread's resources automatically garbage collected? Or is this a memory leak?
def get_data(self,id):
t = threading.Thread(target=self.get_data_in_thread,args=(id,))
t.daemon = True
t.start()
my_processor = Processor()
my_processor.get_data(17)
time.sleep(30)
当守护程序线程中的工作在get_data_in_thread
中完成时
在该线程中分配的内存是否会自动释放,或者是否可以使用特定命令自行终止自己的守护程序线程?像del()或类似的东西?
谢谢!
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)