[Tutor] Using time module to count off seconds before an event

Magnus Lyckå magnus@thinkware.se
Wed Jun 18 21:45:40 2003


At 20:18 2003-06-18 +0100, valhalla wrote:
>I am wanting to modify a guessing game script I have so that the player is
>given x number of seconds (e.g. 60 seconds) during which to guess the answer
>before time's up and game is over.

You might want to look at the threading module and Timer
objects. See
http://starship.python.net/crew/aahz/OSCON2001/index.html

This isn't trivial though...

If some piece of your code is waiting at a "answer = raw_input()",
I don't think there is any way in Python to interrupt that.

Obviously, it's easy to see after the answer was given if it
was supplied within 60 seconds or not...

If you use a GUI you have different possibilities to for
instance disable a text box or close a window when a certain
amount of time has passed.


--
Magnus Lycka (It's really Lyckå), magnus@thinkware.se
Thinkware AB, Sweden, www.thinkware.se
I code Python ~ The Agile Programming Language