May-04-2021, 01:55 AM
(This post was last modified: May-04-2021, 06:12 AM by Yoriz.
Edit Reason: Added code tags
)
I want to schedule a task and use the result of the task while the schedule is being running.
For example, once in every minute I want to get the current time and assigned it to a variable call "now4". So the "now4" value should get updated every minute.
Then from "now4", I want to deduct a previously assigned datetime variable "custom_date_time". The user is going to check this difference by running this part of the code on his own.
So user should have the access to updated "now4" value to get the difference.
How can I get this done.
For example, once in every minute I want to get the current time and assigned it to a variable call "now4". So the "now4" value should get updated every minute.
Then from "now4", I want to deduct a previously assigned datetime variable "custom_date_time". The user is going to check this difference by running this part of the code on his own.
So user should have the access to updated "now4" value to get the difference.
How can I get this done.
from datetime import datetime import schedule import time def my_task(): now4 = datetime.now() print(now4) return now4 schedule.every(1).minutes.do(my_task) custom_date_time = datetime(2021, 5, 1, 17, 30, 29, 431717) while True: schedule.run_pending() time.sleep(1) print(custom_date_time, "Time difference", now4-custom_date_time )