Python 验证是否已正确执行APScheduler任务
我试图使用APScheduler库在两个特定时间执行作业:太平洋标准时间凌晨1点和太平洋标准时间凌晨2点 有点不知所措,我正试图找出我做错了什么。以下是我目前的代码:Python 验证是否已正确执行APScheduler任务,python,python-2.7,datetime,scheduled-tasks,apscheduler,Python,Python 2.7,Datetime,Scheduled Tasks,Apscheduler,我试图使用APScheduler库在两个特定时间执行作业:太平洋标准时间凌晨1点和太平洋标准时间凌晨2点 有点不知所措,我正试图找出我做错了什么。以下是我目前的代码: #!/usr/bin/python import sys import re import urllib import csv import urllib2 import logging import datetime from apscheduler.schedulers.blocking import BlockingS
#!/usr/bin/python
import sys
import re
import urllib
import csv
import urllib2
import logging
import datetime
from apscheduler.schedulers.blocking import BlockingScheduler
sched = BlockingScheduler()
logging.basicConfig()
def main():
#Make a rest call, store the output in a csv, close the file.
...
f.close()
sched.add_job(my_job, 'date', run_date = '2015-12-15 01:00:00', args=['text'])
try:
sched.start()
print(datetime.datetime.now())
except (KeyboardInterrupt):
logger.debug('Terminating...')
print (datetime.datetime.now())
当前时间是太平洋标准时间12:16,我刚刚运行了上面的脚本,它在作业时间12:30:30之前执行并创建了文件;这是为了测试目的
所以,我试图找出我在使用APScheduler方面的错误
我想改进这段代码,我可以更改哪些内容?如果您想每次在特定时间运行代码,您应该使用cron触发器:
sched.add_job(my_job, 'cron', hour='1,2', args=['text'])
为了更好地调试,请执行以下操作:
logging.basicConfig(level=logging.DEBUG)