def run(self): sched = BackgroundScheduler() sched.daemonic = False self.sensors = Sensors() self.lighting = Lighting(1) try: sched.add_job(self.sensors.run, 'interval', minutes=1, start_date='2016-01-01 09:00', misfire_grace_time=10) # sched.add_job(self.lighting.run, 'interval', minutes=1, # start_date='2016-01-01 09:00', misfire_grace_time=10) sched.start() while True: pass except KeyboardInterrupt: print 'Keyboard Interrupted' try: sys.exit(0) except SystemExit: os._exit(0)
from apscheduler.schedulers.background import BackgroundScheduler from apscheduler.triggers.cron import CronTrigger import time from scrapy.crawler import CrawlerProcess from scrapy.utils.project import get_project_settings from Jobspider.spiders.job_test import Jobpythonspider def crawl(crawler, spider): crawler.crawl(spider) crawler.start() if __name__ == '__main__': settings = get_project_settings() crawler = CrawlerProcess(settings) spider = Jobpythonspider() scheduler = BackgroundScheduler() scheduler.daemonic = False cron = CronTrigger(second='*/30') scheduler.add_job(crawl, cron, args=[crawler, spider]) scheduler.start() while True: time.sleep(1000)
from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.support.ui import Select from selenium.common.exceptions import NoSuchElementException from tkinter import * import time from apscheduler.schedulers.background import BackgroundScheduler from apscheduler.executors.pool import ProcessPoolExecutor from lxml import html """MAKE QUIT BUTTON ON TIMER WINDOW DESTROY PROGRAM. INCLUDE CENTER PAUSE BUTTON THAT DOES WHAT QUIT DOES NOW""" first_time = True #setting the scheduler in order to use later in script ap_scheduler = BackgroundScheduler() executors = {'default': ProcessPoolExecutor()} ap_scheduler.configure(executors=executors) ap_scheduler.daemonic = True ap_scheduler.start() #variable made in order to pass things by raising exception skip_rest_of_function = False def timer(username, password, term, crn1): ap_scheduler.add_job(submit_crn, 'interval', seconds=timer_as_integer, args=(username, password, term, crn1)) def submit_crn(username, password, term, crn1): """Happens when user presses RUN in order to register for CRN"""
except: pass @app.cli.command('update') #TODO def redownload_primary_maps(): try: shutil.rmtree('app/map_files') os.mkdir('app/map_files') except: pass #Creates a background scheduled task for the map update method sched = BackgroundScheduler() sched.daemonic = True sched.start() sched.add_job(update, 'cron', day='1st tue', hour='2', misfire_grace_time=None) sched.print_jobs() #logging.basicConfig(filename='log.log',format='%(asctime)s %(message)s', level=logging.DEBUG) format = logging.Formatter('%(asctime)s %(message)s') logFile = 'log.log' my_handler = RotatingFileHandler(logFile, mode='a', maxBytes=5 * 1024 * 1024, backupCount=2, encoding=None,
def timing_background(func, timing_type='interval', seconds=2): scheduler = BackgroundScheduler() scheduler.daemonic = False scheduler.add_job(func, timing_type, seconds=seconds) scheduler.start()