0

After starting my thread if I quit my python program, is the thread killed ? If not how can my thread be killed after quitting my program ?

I created the thread like this:

self.thread = threading.Thread(target=self.start_thread)
self.thread.start()

In start_thread there's a while True and I don't want it to stop before leaving the program

Tomerikoo
  • 15,737
  • 15
  • 35
  • 52
Hydro
  • 15
  • 4
  • It depends on how you created you thread. Give us more detail, give us some code or examples. – Jao Sep 16 '20 at 12:36
  • All threads spawned by a process will exit when the process exits. If you want something to continue running after your process quits, you would need to spawn a subprocess to manage those threads. – larsks Sep 16 '20 at 13:13
  • 1
    You probably want your thread to be [`daemon`](https://docs.python.org/3/library/threading.html#threading.Thread.daemon) – Tomerikoo Sep 16 '20 at 13:13
  • You don't need to do `self.thread.daemon = True`, you can do it inside the constructor: `self.thread = threading.Thread(target=self.start_thread, daemon=True)` – Tomerikoo Sep 16 '20 at 13:30

0 Answers0