Created
January 27, 2015 09:04
-
-
Save jackgolding/8d35defc53cd18e85627 to your computer and use it in GitHub Desktop.
[APSCHEDULER] cron jobs administrating a scheduled job
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from apscheduler.jobstores.base import JobLookupError | |
from apscheduler.schedulers.background import BackgroundScheduler | |
import time | |
def hello(): | |
print(time.localtime().tm_sec) | |
def kill_hello(scheduler): | |
try: | |
scheduler.remove_job('hello_job') | |
except JobLookupError: | |
return | |
def start_hello(scheduler): | |
scheduler.add_job(hello, 'interval', seconds=2, id='hello_job') | |
if __name__ == '__main__': | |
scheduler = BackgroundScheduler() | |
scheduler.add_job(kill_hello, 'cron', second=0, id='kill_hello', args=[scheduler]) | |
scheduler.add_job(start_hello, 'cron', second=30, id='start_hello', args=[scheduler]) | |
scheduler.start() | |
while True: | |
time.sleep(10) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment