1

I've tried using the the solution posted here:

How would I stop a while loop after n amount of time?

but that loop doesn't end with the function im running that accepts inputs. How do I force function5 to exit?

    while True:
                test = 0
                if test == 5 or time.time() > timeout:
                    print "time's out!"
                    break
                test = test - 1
                function5()
   def function5():
                receiver = raw_input("enter something: ")
Community
  • 1
  • 1
fry bell
  • 23
  • 6
  • Do you want to do this manually or do you want it to timeout automatically? – cs95 May 01 '17 at 08:00
  • Possible duplicate of http://stackoverflow.com/questions/1335507/keyboard-input-with-timeout-in-python – cs95 May 01 '17 at 08:03

1 Answers1

0

You've already identified your problem. This won't work because when you call raw_input() the program will wait forever until the user types something, and what you want is for the timeout to somehow interrupt raw_input().

Here is a *nix-only solution:

Keyboard input with timeout in Python

Community
  • 1
  • 1
BoarGules
  • 16,440
  • 2
  • 27
  • 44
  • UPDATE: http://stackoverflow.com/a/3911477/7927496 Paul's code with thread seems do what I want to do. Although I haven't figured out how it works completely because threads are new to me. I still managed to tweak it a little bit to fit my code – fry bell May 01 '17 at 16:40