Threading Python interrompe o sono
Existe uma maneira em python interromper um thread quando ele está dormindo? (Como podemos fazer em java)
Estou procurando por algo assim.
import threading
from time import sleep
def f():
print('started')
try:
sleep(100)
print('finished')
except SleepInterruptedException:
print('interrupted')
t = threading.Thread(target=f)
t.start()
if input() == 'stop':
t.interrupt()
O thread está inativo por 100 segundos e se eu digitar 'stop', ele interrompe