在下一整秒启动python调度程序

在下一整秒启动python调度程序,python,apscheduler,Python,Apscheduler,我已经用提供的示例测试了APscheduler: from datetime import datetime import time import os from apscheduler.schedulers.background import BackgroundScheduler def tick(): print('Tick! The time is: %s' % datetime.now()) if __name__ == '__main__': schedul

我已经用提供的示例测试了APscheduler:

from datetime import datetime
import time
import os

from apscheduler.schedulers.background import BackgroundScheduler


def tick():
    print('Tick! The time is: %s' % datetime.now())


if __name__ == '__main__':
    scheduler = BackgroundScheduler()
    scheduler.add_job(tick, 'interval', seconds=3)
    scheduler.start()
    print('Press Ctrl+{0} to exit'.format('Break' if os.name == 'nt' else 'C'))

    try:
        # This is here to simulate application activity (which keeps the main thread alive).
        while True:
            time.sleep(2)
    except (KeyboardInterrupt, SystemExit):
        # Not strictly necessary if daemonic mode is enabled but should be done if possible
        scheduler.shutdown()
输出:

Tick! The time is: 2020-09-14 00:56:23.225999
Tick! The time is: 2020-09-14 00:56:28.226864
...
在下一整秒/下一整10秒/下一整分钟/启动计划程序的最佳方式是什么。。。所以输出更可读

下一轮第二次开始时的输出示例:

Tick! The time is: 2020-09-14 00:56:23.000000
Tick! The time is: 2020-09-14 00:56:28.000000
...

参考文档,您可以设置开始日期:


参考文档,您可以设置开始日期:

    scheduler.add_job(tick, 'interval', seconds=3, 
                 start_date='2021-06-23 11:36:00', end_date='2021-06-23 11:37:00')