Tricks with timers
valhalla
tireseas at onetel.com
Fri Jun 20 15:25:43 EDT 2003
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.
I don't want to use sys.exit(0), because I don't want the program to stop,
just the one function. Would I be using SIGINT or SIGKILL or something along
those lines to reset the game for a new time limit to be entered? The
documentation that I've looked at for this discuss these options, but to be
honest I cannot really figure out whether they are what I am looking for
given the problem described.
TIA
Andy
--
====================
|| Reg. Linux User: 313143 ||
====================
Sign the Petition:
http://www.PetitionOnline.com/endtcpa1/
More information about the Python-list
mailing list