我正在尝试学习如何使用 Python 的 apscheduler 包,但它会定期抛出以下错误:
No handlers could be found for logger "apscheduler.scheduler"
此消息似乎与计划作业中的错误有关,例如,使用 jobTester 作为计划作业,以下代码在 jobTester 中使用未定义的变量 (nameStr0) 给出了上述错误消息:
from apscheduler.scheduler import Scheduler
from apscheduler.jobstores.shelve_store import ShelveJobStore
from datetime import datetime, timedelta
from schedJob import toyJob
def jobTester(nameStr):
outFileName = nameStr0 + '.txt'
outFile = open(outFileName,'w')
outFile.write(nameStr)
outFile.close()
def schedTester(jobList):
scheduler = Scheduler()
scheduler.add_jobstore(ShelveJobStore('example.db'),'shelve')
refTime = datetime.now()
for index, currJob in enumerate(jobList):
runTime = refTime + timedelta(seconds = 15)
jobName = currJob.name + '_' + str(index)
scheduler.add_date_job(jobTester, runTime, name = jobName,
jobstore = 'shelve', args = [jobName])
scheduler.start()
stopTime = datetime.now() + timedelta(seconds = 45)
print "Starting wait loop .....",
while stopTime > datetime.now():
pass
print "Done"
def doit():
names = ['Alan','Barbara','Charlie','Dana']
jobList = [toyJob(n) for n in names]
schedTester(jobList)
这可以通过运行此代码(存储在文件 schedTester.py 中)来查看,如下所示:
>>> import schedTester
>>> schedTester.doit()
No handlers could be found for logger "apscheduler.scheduler"
Starting wait loop ..... Done
但是,当我将 nameStr0 替换为 nameStr (即变量名的正确拼写)时,代码运行良好,没有错误消息。
如何为 apscheduler.scheduler 创建记录器?我是否在处理配置调度程序的文档部分中遗漏了什么
我将这个记录器视为某种 stderr 是否正确?如果是这样,我将在哪里寻找它(如果这不是由我设置它的方式决定的)