python - To execute a function every x minutes: sched or threading.Timer? -


i need program execution of give method every x minutes.

i found 2 ways it: first using sched module, , second using threading.timer.

first method:

import sched, time s = sched.scheduler(time.time, time.sleep) def do_something(sc):      print "doing stuff..."     # stuff     sc.enter(60, 1, do_something, (sc,))  s.enter(60, 1, do_something, (s,)) s.run() 

the second:

import threading  def do_something(sc):      print "doing stuff..."     # stuff    t = threading.timer(0.5,do_something).start()  do_something(sc) 

what's difference , if there 1 better other, one?

from the sched documentation:

in multi-threaded environments, scheduler class has limitations respect thread-safety, inability insert new task before 1 pending in running scheduler, , holding main thread until event queue empty. instead, preferred approach use threading.timer class instead.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -