Tricks with timers

Jp Calderone exarkun at intarweb.us
Fri Jun 20 17:08:40 EDT 2003


On Fri, Jun 20, 2003 at 08:25:43PM +0100, valhalla wrote:
> Hello
> 
> To get around the previously stated problem of using a timer-like function in 
> a guessing game to limit the amount of time a player has to guess the correct 
> number, I have used the following:
> 
>    signal.signal( signal.SIGALRM, timer )
>    signal.alarm( ticktock )
> 
> where timer is a function that prints "Time's Up!!" and 'ticktock' is a 
> variable passed a value from input("time needed: ").
> 
> That actually works quite well. The next piece of the puzzle is to find a way 
> in which I can do the equivalent of a break from the timer, so that if the 
> correct answer is guessed *within* the allotted time, the ticktock is 
> returned to zero and the timer function is suspended until the next game.

  Subsequent calls to signal.alarm() will override whatever the current
alarm timer is.

  Jp





More information about the Python-list mailing list