I think you may want to set the thread as a daemon thread, so when it is the only thread left running, it will automatically stop. From the documentation: "The entire Python program exits when no active non-daemon threads are left. "