Ending non-daemon threads when shutting down an interactive python session
问题 Please consider the code below: #! /usr/bin/env python3 import threading import time class MyThread(threading.Thread): def __init__(self): super().__init__() self._quit_flag = False def run(self): while not self._quit_flag: print("Thread is alive!") time.sleep(0.500) def request_quit(self): self._quit_flag = True mt = MyThread() mt.start() After saving this as 'test.py' and running 'python3 -i test.py', I get an interactive session, where the thread regularly prints the "Thread is alive!"