multithreading - Python threading interrupt sleep -


is there way in python interrupt thread when it's sleeping? (as can in java)

i looking that.

  import threading   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() 

the thread sleeping 100 seconds , if type 'stop', interrupts

how using condition objects: https://docs.python.org/2/library/threading.html#condition-objects

instead of sleep() use wait(timeout). "interrupt" call notify().


Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -