Running apschduler in Python script as a daemon?

Go To StackoverFlow.com

0

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()
  • When I run this on the command prompt, it exits immediately:

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

  • How can I makde this run as a daemon?
2012-04-03 20:32
by daydreamer
The resoulution is here : http://stackoverflow.com/questions/5835600/apscheduler-not-startin - daydreamer 2012-04-03 20:50


0

Write your main() as below.

def main():
    [... your_code_as_in_your_question ...]
    while (True):
        pass

Additionally it shouldn't hurt to consider PEP 3143.

2012-10-02 20:50
by KAcper Perschke