How can i stop a thread after 5 seconds? I want to print "Hello World" every seconds and then stop after 5 seconds. This is my code:
import threading
def printthis():
threading.Timer(1.0, printthis).start()
print("Hello, World!")
printthis()
How can i stop a thread after 5 seconds? I want to print "Hello World" every seconds and then stop after 5 seconds. This is my code:
import threading
def printthis():
threading.Timer(1.0, printthis).start()
print("Hello, World!")
printthis()
How about this:
def printthis():
print_count = 0
while print_count < 5: # 5 because print_count will be 5 after printing the 5th time
threading.Timer(1.0, printthis).start()
print("Hello, World!")
print_count += 1
printthis()