Print time on APScheduler

最后都变了- 提交于 2019-12-25 04:00:25

问题


How do you print the time with specific timezone used by APScheduler. I used an specific timezone for its BackgroundScheduler. When I used the 'cron' job to do a task on a specific time, it didn't went well. My suspicion is it's using a different time.

from flask import Flask
from datetime import datetime
from oauth2client.service_account import ServiceAccountCredentials
from mysql.connector import Error
from threading import Thread
from apscheduler.schedulers.background import BackgroundScheduler
from apscheduler.executors.pool import ThreadPoolExecutor, ProcessPoolExecutor

import datetime
import time
import gspread
import mysql.connector

app = Flask(__name__)

executors = {
    'default': ThreadPoolExecutor(16),
    'processpool': ProcessPoolExecutor(4)
}

sched = BackgroundScheduler(timezone='Asia/Seoul', executors=executors)

def job_1():
    print("YES.")

def job_2():
    print("I'm working working...")
    print(datetime.datetime.now())

sched.add_job(job_1, 'cron', hour=17, minute=19)
sched.add_job(job_2, 'interval', seconds=10)



@app.route('/')
def homepage():
    return '<h1>Hello World!</h1>'


if __name__ == '__main__':
    sched.start()
    app.run(debug=True, use_reloader=False)

I needed to run job_1 on 5:19 on my Computer, but I guess I specified a timezone for APScheduler, so it did not execute. I want to know the current time the APSCheduler is using.

UPDATE: When I used timezone=None,

sched = BackgroundScheduler(timezone=None, executors=executors)

It went well, it followed the time on my Computer. Now I just want to print the time of the specified timezone I used in there.

来源:https://stackoverflow.com/questions/52074191/print-time-on-apscheduler

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!