Textdoc
Zipdoc
Writeurl
Loading…
from threading import Thread, Event from time import sleep def interruptThreads(event1, event2): y=input("Waiting for user input") if y == "exit": event1.set() event2.set() def task1(event): while not (event.is_set()): print("The thread is printing data.") sleep(4) print("The thread is stopping.") def task2(event): while not (event.is_set()): print("Here is another printing thread.") sleep(4) print("The second thread is stopping.") if __name__ == '__main__': event1=Event() event2=Event() thread1=Thread(target=task1, args=(event1,)) thread2=Thread(target=task2, args=(event2,)) thread1.start() thread2.start() interruptThreads(event1, event2)