1

I have this code and I run it with a thread but I want to kill it after 1 second '''

 import threading
 import time
 def run(stop):
    for i in range (10):
        print(i)
        time.sleep(0.3)
       
 def main():
    stop_threads = False
    t1 = threading.Thread(target = run, args =(lambda : stop_threads, ))
    t1.start()
    time.sleep(1)
    stop_threads = True
    t1.join()

 main()*
Omar rai
  • 29
  • 5
  • Does [this](https://stackoverflow.com/questions/323972/is-there-any-way-to-kill-a-thread) answer your question? – Tobi208 Feb 03 '22 at 17:00

0 Answers0