2014-10-24 1 views
0

코드를 실행하는 동안 가져 오기 오류가 발생합니다. 스케줄러 모듈을 찾을 수 없습니다. backgroundScheduler()을 사용하여 오류를 우회하려고 시도했을 때 cron과 같은 작업 스케줄링을 지원하지 않는다는 것을 발견했습니다. 즉 add_cron_job입니다. 내가 어디로 잘못 가고 있니?apscheduler가 작동하지 않습니다. 가져 오기 오류 : Scheduler라는 모듈이 없습니다.

import ConfigParser 
import pymysql # Allows us to connect to a database and issue queries 
from time import sleep 
from datetime import datetime 
import threading, time 
import json 
from apscheduler.scheduler import Scheduler 
import os 
import logging 
import smtplib # Import smtplib for the actual sending function 




logging.basicConfig() 
config = None 
sched = Scheduler() 
sched.start() 



#---------------------------------------------------------------------------- 
# init_config_parser 
# Initialize a config parser based on filename 
#---------------------------------------------------------------------------- 
def init_config_parser(): 
    global config 
    config = ConfigParser.SafeConfigParser() 
    config.readfp(open('settings.cfg')) 
    return config 


# This is called when the runReportsScheduler.py file is first run. 
# There is an infinite loop such that the script will never terminate. 

# Every x number of seconds, the script reloads the latest 
# notification schedules from the database. These notification schedules 
# can be changed from the webapp in the configuration page. 
# Then, it reschedules all of the email notifications accordingly. 

# The scheduler calls the function email_send everytime it should be fired. 


def email_send(emails): 

    From = '[email protected]' 
    To = emails 

    message = """Please ignore this email. 


    This is a test e-mail message. 
    """ 
    try : 
     smtpObj = smtplib.SMTP('smtphost.qualcomm.com') 
     smtpObj.sendmail(From, To.split(','), message) # the second parameter expects a list for multiple contacts 
     smtpObj.quit() 
    except SMTPException: 
     print "Error: unable to send email" 

if __name__ == '__main__': 

    init_config_parser() 
    updateInterval = float(config.get("SCHEDULER",'updateInterval')) 
    thisURL = str(config.get("SCHEDULER",'rootURL')) 

    #refreshingFunction(50687,False) 

    i = 0 
    while True: 
     i += 1 
     print "This is the #"+str(i)+" time I am looping, on a "+str(updateInterval)+"s interval" 


     conn = pymysql.connect(host="10.52.244.877", user="wciadmin", passwd="admybutt", db="weekly_reports") 
     cur = conn.cursor(pymysql.cursors.DictCursor) 
     cur.execute("SELECT * FROM reminders_table ORDER BY id DESC") 


     currentJobs = sched.get_jobs() 
     row = cur.fetchone() 
     while row is not None: 
     # this is for each row in the DB 
      thisQuery = row['id'] 


      # delete any current jobs with that query name 
      for job in currentJobs: 
       if int(job.name) == int(thisQuery): 
        sched.unschedule_job(job) 

     thisRuntimes = row['runtimes'].split(";") 
     if len(thisRuntimes) > 0 and row['runtimes'] != "": 
      for thisSchedule in thisRuntimes: 
       daysOfWeek = thisSchedule.split("-")[0] 
       times = thisSchedule.split("-")[1].split(",") 
       for time in times: 
       hour = time.split(":")[0] 
       if hour[0] == "0": 
        hour = hour[1] 
       min = time.split(":")[1] 

       sched.add_cron_job(email_send, day_of_week=daysOfWeek, hour=hour, minute=min, args=[row['emails']]) 
    row = cur.fetchone() 


conn.close() 

sleep(updateInterval) #in seconds 

답변

2

알 수 있습니다. 스케줄러()는 apscheduler v3.0에서 사용되지 않습니다. 버전 2.1.2를 다운로드하고 내 문제를 해결했습니다. v2.1.2에 대한 링크는 다음과 같습니다 :

https://pypi.python.org/pypi/APScheduler/2.1.2#downloads

+1

가 사용되지 않음 - 완전히 제거. –

관련 문제