How to force main thread to close if a sub thread is alive in python?
sys.exit()
and exit()
appears to wait for sub thread to complete?
How to force main thread to close if a sub thread is alive in python?
sys.exit()
and exit()
appears to wait for sub thread to complete?
Turn your sub threads into daemon threads. For example:
class SubThread(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
self.daemon = True # Makes the thread a daemon thread
...
Or
subThread = threading.Thread(...)
subThread.daemon = True
When your program ends, all daemon threads will immediately die. If the sub threads are not daemon threads, then they must be stopped before your program will end. As Serge mentioned in a comment, "Is there any way to kill a Thread in Python?" talks about ways to stop threads.
You may want to look into setting it as a daemon thread. See information about daemon threads at Daemon Threads Explanation. Then it shouldn't wait for that thread to complete.