I have a
job.py which has the following code.
import datetime import logging import sys import os from apscheduler.scheduler import Scheduler from src.extractors.pExtractor import somejob def run_job(): start = datetime.datetime.now() logging.debug('Proposal extraction job starting') somejob.main() end = datetime.datetime.now() duration = end - start logging.debug('job completed , took ' + str(duration.seconds) + ' seconds') def main(): logging.basicConfig(filename='/tmp/pExtractor.log', level=logging.DEBUG,format='%(levelname)s[%(asctime)s]: %(message)s') sched = Scheduler() sched.start() sched.add_interval_job(run_job, minutes=2) if __name__ == '__main__': main()
INFO[2012-04-03 13:31:02,825]: Started thread pool with 0 core threads and 20 maximum threads INFO[2012-04-03 13:31:02,827]: Scheduler started INFO[2012-04-03 13:31:02,827]: Added job "run_job (trigger: cron[minute='2'], next run at: 2012-04-03 14:02:00)" to job store "default" INFO[2012-04-03 13:31:02,828]: Shutting down thread pool
main() as below.
def main(): [... your_code_as_in_your_question ...] while (True): pass
Additionally it shouldn't hurt to consider PEP 3143.