python - return 在 threading.Thread class 上释放所有内存吗?
python - does return on a threading.Thread class free all the memory?
我有这个 class,它有时会调用 on_close(),我如何确保我的线程将关闭并释放所有使用的内存?在 on_close() 中放入 return 就够了吗?
另外,运行 500+线程安全吗?菜鸟问题,我知道..但我正在努力学习!
class MyClass(threading.Thread):
def __init__(self): pass
def do_stuff(self): pass
def on_close(self):
more_stuff()
return
使用 gc 模块可以帮助您强制垃圾收集器 运行。
关于你的第二个问题,在现代 PC 中你可以 运行 最多大约 4000 个线程,但是 Python 的 GIL creates an absurd situation, where running multiple python threads on a multi-core PC will be slower than running the same program on a single-core. David beazley 解释这在他的一次演讲中非常完美。
我有这个 class,它有时会调用 on_close(),我如何确保我的线程将关闭并释放所有使用的内存?在 on_close() 中放入 return 就够了吗? 另外,运行 500+线程安全吗?菜鸟问题,我知道..但我正在努力学习!
class MyClass(threading.Thread):
def __init__(self): pass
def do_stuff(self): pass
def on_close(self):
more_stuff()
return
使用 gc 模块可以帮助您强制垃圾收集器 运行。
关于你的第二个问题,在现代 PC 中你可以 运行 最多大约 4000 个线程,但是 Python 的 GIL creates an absurd situation, where running multiple python threads on a multi-core PC will be slower than running the same program on a single-core. David beazley 解释这在他的一次演讲中非常完美。