1

I'm starting out with python and want to know how to set a time limit for the user to input something using the input() function. I have looked at other questions and cant find one that:

a) I can understand b) Works for me.

I am on Python 3.4 and I am a complete noob. Thank you for taking the time to answer my question!:)

I am also on windows.

Tom
  • 33
  • 6

1 Answers1

0

Here's an earlier post that answers your question.

Basically you use the signal module to send an alarm signal to your program an interrupt the input command after a timeout.

I'm not sure there's a simpler way to do this, but to outline it broadly the "interrupted" function can be any function you like, it gets called when the timeout runs out. When the alarm triggers it raises an exception which sends you to the 'except block' of the input function.

Actually, looking at the example, I think input is a built-in function, so that function should really be called something else!

Community
  • 1
  • 1
Julian
  • 2,483
  • 20
  • 20