Reputation: 3
I am making a game in py2.7 and I want to know how to create a timer running in the background of my code and when time is up, a command is executed. Any help is appreciated.
Upvotes: 0
Views: 131
Reputation: 4078
Depending on what you are using for the game you will need to refresh the output so it doesn't print line by line, but this is a simple way to count down from 60 seonds:
from time import sleep
time = 60
while time != 0:
print time
time -= 1
sleep(1)
Upvotes: 0
Reputation: 36043
You probably want threading.Timer. The sched module might also be useful.
Upvotes: 1