0

I try to stop the Input function, but it doesn't work out. It works to stop the Timer after 4 Inputs, but the Timer won't stop the input function. I'm working with Windows, so I can't use Signal.

from threading import Thread
from threading import Timer
import sys
x=3
def killThread ():
    print ("timeout")
    return
    sys.exit(0)
def function ():
    global x
    summa = 0
    if t.isAlive:
        while x>=0:
            y = int(input ("Number: "))
            x=x-1
            summa = summa + y
            print (summa)
        print ("it's enough")
        t.cancel ()
        sys.exit(0)

if __name__ == '__main__':

t1 = Thread (target=function, daemon=True)
t1.setDaemon (True)
t = Timer(5.0, killThread)
t.start()
t1.start ()
Kari
  • 1
  • 2

0 Answers0