Question is in the title.
Code example:
class A:
def start_thread(self):
t1 = threading.Thread(target=something)
t1.start()
a = A()
a.start_thread()
a = A()
So, what happens to the thread, which we started?
threading
模块本身保留对每个活动Thread
对象的引用,因此即使引用消失,正在运行的线程也将继续运行。
线程保存在 Python 运行时的单独注册表中,您可以通过调用threading.enumerate
( https://docs.python.org/3/library/threading.html#threading.enumerate ) 来“查看”它们 - 这是没有什么不同,然后不保留对以任何其他方式启动的线程的引用。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.