What happens to thread started in the class instance when all references to the instance are destroyed (Python)?

Alex Bodnya :

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?

chepner :

The threading module itself keeps a reference to each active Thread object, so a running thread will continue to run even if the reference goes away.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=319232&siteId=1