I am trying to stop a script I wrote automatically but I can't find a way to stop the threads as well as the main code.
import time
import threading
import sys
def thread():
while True:
print('hi')
time.sleep(2)
t1 = threading.Thread(target=thread)
t1.start()
print('using sys.exit() in 5...')
time.sleep(1)
print('4')
time.sleep(1)
print('3')
time.sleep(1)
print('2')
time.sleep(1)
print('1')
time.sleep(1)
sys.exit()
This is a dummy code^. I'm no expert in python and I only know the basics. Is there a way and if so, how? Thanks!