0

In python I want to set an alarm, because I want to print game over after 5 seconds. All I need is a timer. I know this is a stupid question, but I searched the website, and found no answer. Please help.

Mariba
  • 39
  • 8
  • 4
    I think we are getting too cruel with instant downvoting. Legitimately, this is a hard thing to find for a newer Pythonista. – dawg Sep 07 '14 at 23:27
  • i lost three votes for another question so i had to delete it – Mariba Sep 07 '14 at 23:37
  • people even wanted me to delete the question – Mariba Sep 07 '14 at 23:38
  • 3
    Pls note that Mariba is 13 years old and studying Python after soccer. C'mon folks -- everyone started somewhere. – the wolf Sep 07 '14 at 23:46
  • @PadraicCunningham, it is true – Mariba Sep 08 '14 at 00:03
  • Being 13 is no excuse for posting questions with no effort. The sympathy upvotes are ridiculous. If you want to be helpful at least edit if you think it can be made useful. – Wooble Sep 08 '14 at 00:04
  • @Mariba, this is the internet and I am Batman, btw do you also do a bit of the ole Doogie Howser @bridgewaterinternalmedicine? – Padraic Cunningham Sep 08 '14 at 00:10
  • 1
    @Wooble: As I Google `python create timer` it does take a bit of parsing to separate the answers with 'sleep' vs the correct answer of using threading. It is hard when you are at a point of not even knowing where to start and one pointer makes all the difference. Look at answers of several years ago like [Creating a new dict in Python](http://stackoverflow.com/questions/8424942/creating-a-new-dict-in-python) with 62 up votes. Are we saying this question is more lame than that one? I repeat my earlier comment -- I think the SO community has tipped in the direction of being too cruel. – dawg Sep 08 '14 at 00:21

1 Answers1

4

You can use threading.Timer like this:

from threading import Timer

def gameover():
    print "Game Over"

t = Timer(5.0, gameover)
t.start()
enrico.bacis
  • 30,497
  • 10
  • 86
  • 115