我有job.py
,其中包含以下代码。
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]:启动了0核心线程的线程池 和20个最大线程信息[2012-04-03 13:31:02,827]:调度程序 启动INFO [2012-04-03 13:31:02,827]:添加了作业“run_job(触发器: cron [分钟='2'],下次运行于:2012-04-03 14:02:00)“到工作店 “default”INFO [2012-04-03 13:31:02,828]:关闭线程池
答案 0 :(得分:0)
写下您的main()
,如下所示。
def main():
[... your_code_as_in_your_question ...]
while (True):
pass
此外,考虑PEP 3143也不应该受到伤害。