Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

running clock and triggering

Tags:

python

constantly running a clock and trigger an other function for every 5 seconds.

Please give me idea how to do this.

Thanks a bunch

like image 295
sparls Avatar asked Jun 17 '26 09:06

sparls


1 Answers

>>> import sched, time
>>> s = sched.scheduler(time.time, time.sleep)
>>> def print_time():
...     s.enter(5, 1, print_time, ())
...     print "From print_time", time.time()
... 
>>> s.enter(0, 1, print_time, ())
Event(time=1265846894.4069381, priority=1, action=<function print_time at 0xb7d1ab1c>, argument=())
>>> s.run()
From print_time 1265846894.41
From print_time 1265846899.41
From print_time 1265846904.42
From print_time 1265846909.42
like image 58
John La Rooy Avatar answered Jun 18 '26 21:06

John La Rooy