В расписании модуля Python, как я могу распечатать следующее время выполнения один раз после запуска задания?Python

Программы на Python
Гость
В расписании модуля Python, как я могу распечатать следующее время выполнения один раз после запуска задания?

Сообщение Гость »


After i run pending jobs with python's schedule module, I'd like to print once "next job scheduled at {next_job_time}".

This code prints the message every second which isn't what I want :

import schedule import time def Job(): #doing something... schedule.every(1).hours.do(Job) while True: schedule.run_pending() print(f"next job scheduled at {schedule.next_run()}") time.sleep(1) I thought about using a decorator around Job, that prints the message right after job is executed, but when I do this the time printed is that of the current execution and not the next one. I think this because decorators do their stuff before schedule marks the job as completed and updates the jobs list.

Any idea how I can print my message once right after a job completes and still get the correct next_run time?


Источник: https://stackoverflow.com/questions/780 ... er-job-run

Вернуться в «Python»