better scheduler with correct sleep times
James Mills
prologic at shortcircuit.net.au
Sat Oct 18 20:37:03 EDT 2008
On Sat, Oct 18, 2008 at 10:09 PM, qvx <qvx3000 at gmail.com> wrote:
[ ... ]
> Is there a better way or some library that does that?
How about this ?
$ ./timerexamples.py
Time: 1224375945.336958
Timer 2 fired at: 1224375945.840600
Timer 1 fired at: 1224375955.336889
<code>
#!/usr/bin/env python
import time
from circuits.core import Manager, Component, Event, listener
from circuits.timers import Timer
class TimerExamples(Component):
@listener("timer1")
def onTIMER1(self):
print "Timer 1 fired at: %f" % time.time()
@listener("timer2")
def onTIMER2(self):
print "Timer 2 fired at: %f" % time.time()
m = Manager()
m += TimerExamples()
timers = []
timers.append(Timer(10, Event(), "timer1"))
timers.append(Timer(0.5, Event(), "timer2"))
for timer in timers:
m += timer
print "Time: %f" % time.time()
while True:
try:
m.flush()
for timer in timers:
timer.poll()
except KeyboardInterrupt:
break
</code>
cheers
James
--
--
-- "Problems are solved by method"
More information about the Python-list
mailing list