python - Function which executes when the date changes -


i need function execute every time date changes. i'm checking in loop see if date changed, i'm looking more effective method....in python

any appreciated

what want schedule function run @ time. need scheduling mechanism. could, of course, write 1 yourself, best way go use library you.

apscheduler mature library sort of thing.

docs: http://apscheduler.readthedocs.org/en/latest/

pypi: https://pypi.python.org/pypi/apscheduler/3.0.0

example

here quick little example

from apscheduler.schedulers.background import blockingscheduler  scheduler = blockingscheduler()  @scheduler.scheduled_job('interval', seconds=5, timezone='utc') def hello():     print('hello!')  scheduler.start() 

this run function hello every 5 seconds. can change seconds=5 days=1 have run once day. there much more configuration can do, you'll want read documentation. able express date time format want, including cron.

it supports different types of schedulers, instance chose blockingscheduler because wanted entire program run function of scheduling mechanism (so try out on own system). can use, instance, backgroundscheduler allow schedule tasks within program in efficient manner not block main thread (fixes going in loop forever problem).


Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

visual studio 2010 - Connect to informix database windows form application -

android - Associate same looper with different threads -