def main():
    t1_stop = threading.Event()
t1 = threading.Thread(target=thread1, args=(1, t1_stop))
t2_stop = threading.Event()
t2 = threading.Thread(target=thread2, args=(2, t2_stop))
time.sleep(duration)
t2_stop.set()

def thread1(arg1, stop_event):
    while not stop_event.is_set():
        pass
Stopping a thread after a certain amount of time