best way to create a timer

A

Alexnb

I am wondering what is the best way to create a timer, like an alarm, once it
reaches a time, it triggers an event. I have a way of doing this but it
seems like it isn't good at all. If it helps at all I am using a Tkinter,
but that probably doesn't mean much. The way I was doing it was using a
while loop, and just saying while current time is not = to trigger time, do
nothing, and when it is, do event.
 
S

subhabrata.iisc

You can think of doing with import time module and time.sleep(n) but
you have to calculate n in seconds.
Subhabrata.
 
G

Giampaolo Rodola'

I am wondering what is the best way to create a timer, like an alarm, once it
reaches a time, it triggers an event. I have a way of doing this but it
seems like it isn't good at all. If it helps at all I am using a Tkinter,
but that probably doesn't mean much. The way I was doing it was using a
while loop, and just saying while current time is not = to trigger time, do
nothing, and when it is, do event.

I think that threading.Timer could be what you're searching for.


--- Giampaolo
http://code.google.com/p/pyftpdlib/
 
R

Rhamphoryncus

I am wondering what is the best way to create a timer, like an alarm, once it
reaches a time, it triggers an event. I have a way of doing this but it
seems like it isn't good at all. If it helps at all I am using a Tkinter,
but that probably doesn't mean much. The way I was doing it was using a
while loop, and just saying while current time is not = to trigger time, do
nothing, and when it is, do event.

Tkinter makes a big difference here. Like most (all?) event loops, it
provides a way to call a function after a specified amount of time.

Here's two pages I found:

http://mail.python.org/pipermail/python-list/2001-August/101233.html
http://www.astro.washington.edu/owen/TkinterSummary.html#After

Note that it only fires once. If you want it to fire again you're
callback will have to setup another timer.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top