xxxxxxxxxx
# Tldr; use _thread.interrupt_main()
import time
import threading
import _thread
def task():
time.sleep(3) # block for 3 seconds
print('Interrupting main thread now')
_thread.interrupt_main() # interrupt main
# start the new thread
thread = threading.Thread(target=task).start()
# run main loop and wait for exception
while True:
print('Main thread waiting...')
time.sleep(0.5)