According to the documentation: https://docs.python.org/3/library/threading.html
A thread can be flagged as a “daemon thread”. The significance of this flag is that the entire Python program exits when only daemon threads are left. The initial value is inherited from the creating thread. The flag can be set through the daemon property or the daemon constructor argument.
Sample code:
thread = threading.Thread(target=MultiHandler().network, args=(conn, data), daemon=True)
thread.start()
Refering to many other StackOverflow answers, it is not clear to me if daemon threads are forced to close when the main thread calls sys.exit()
join()to wait for the thread before callingsys.exit()? - X3Gammasys.exit()is less than clear about multi-threaded programs, but if you look closely, you'll see that it says thatsys.exit()doesn't do anything but throw an exception. So, it will only terminate the one thread that calls it, and only if the thread has no handler that swallows the exception. - Solomon Slow