t2.start()
try:
    while 1:
        time.sleep(0.1)
except KeyboardInterrupt:
    print('attempting to close threads. Max wait =', max(d1, d2))
run_event.clear()
t1.join()
t2.join()
print('threads successfully closed')
if __name__ == '__main__':
    main()
Закрытие всех потоков прерыванием клавиатуры