Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在使用 ncurses 编写一个小型 python 游戏。我想连续显示倒数计时器并同时接受用户输入。
在 main 函数中,我创建了一个线程来显示倒数计时器,然后放置一个循环来接收用户的输入。
问题:当玩家说“退出”游戏并没有退出时,游戏只有在计时器线程倒计时到零后才结束。如何杀死介于两者之间的计时器线程?
将您的计时器线程标记为守护进程,即已设置
thread.daemon = True
(thread您的计时器线程对象在哪里)在调用thread.start().
thread
thread.start()