我正在编写一些简单的代码,我使用 Pygame 进行图形处理,并且我有一个线程可以绘制所有内容。当我调用 sys.exit() 或只是 ctrl+c 时,主程序退出,但线程似乎仍然存在。我想我需要先把它关掉。我该怎么做?
示例:
import threading
class Bla(threading.Thread):
def run(self):
print "I draw here"
Bla().start()
while True:
if user_wants_to_end:
sys.exit()
当我确实想退出时,程序不会退出!如何关闭线程?
最佳答案
Python 程序在所有非守护线程完成后退出。
class Bla(threading.Thread):
daemon = True # Make the thread daemon
def run(self):
print "I draw here"
关于python - 如何退出正在运行线程的Python程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6694916/