Тут по exit(0) работа не завершается.
import threading import msvcrt import time stop = True def time_th(): global stop while stop: stop = False for i in range(5,0,-1): time.sleep(2) print(i) exit(0) trh = threading.Thread(target=time_th) trh.start() key = None while key != b'\x1b': key = msvcrt.getch() stop = True print(key)
Тут после timer.run(), код вообще не отрабатывает.
import threading import msvcrt import time class time_(threading.Thread): def __init__(self, ): super(time_, self).__init__() self.t_worck = True def run(self): while self.t_worck: self.t_worck = False for i in range(5,0,-1): time.sleep(2) print(i) exit(0) def m_continue(self): self.t_worck = True timer = time_() timer.run() key = None while key != b'\x1b': key = msvcrt.getch() timer.m_continue() print(key)