python how to kill a running thread code example
Example: kill threading in python
import random
import threading
import time
def bg_thread():
for i in range(1, 30):
print(f'{i} of 30 iterations...')
time.sleep(random.random()) # do some work...
print(f'{i} iterations completed before exiting.')
th = threading.Thread(target=bg_thread)
th.start()
th.join()