This commit is contained in:
2024-06-10 10:44:16 +02:00
parent 9256184430
commit 3093557c99
79 changed files with 2747 additions and 189 deletions

View File

@@ -0,0 +1,27 @@
import threading
from threading import Thread
from _thread import interrupt_main
import sys
# task executed in a new thread
def task():
# block for a moment
sleep(3)
# interrupt the main thread
print('Interrupting main thread now')
interrupt_main()
# start the new thread
thread = Thread(target=task)
thread.start()
print(threading.current_thread() == threading.main_thread())
# handle being interrupted
try:
# wait around
while True:
print('Main thread waiting...')
sleep(0.5)
except KeyboardInterrupt:
# terminate main thread
print('Main interrupted! Exiting.')