0

In python, is it possible to run code or perform an action while the script is sleeping like time.sleep()? What I want to do is print a message and gather input from the user only until 10 seconds after the message has been printed. I initially though I could do

print "You have ten seconds to answer the question."
print "The question"
time.sleep(10) and input() simultaneously
print "You are out of time"

Is this possible? If not, is there any way to accomplish the same thing?

Raghav Malik
  • 751
  • 1
  • 6
  • 20

1 Answers1

1

While sleeping you can't do anything. Look for the alarm(2) system call on Unix/Linux to get interrupted after some time.

vonbrand
  • 11,412
  • 8
  • 32
  • 52