Python Forum
Schedule a task and render/ use the result of the task in any given time
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Schedule a task and render/ use the result of the task in any given time
#3
(May-04-2021, 07:07 AM)menator01 Wrote: Not sure if this is what you want
import schedule, time
from datetime import datetime

def my_task():
    custom_time = datetime(2021, 5, 1, 17, 30, 29, 431717)
    now = datetime.now()
    print(f'Custom Time:{custom_time} Current Time: {now} Time Difference: {custom_time-now}')

schedule.every(1).minutes.do(my_task)

while True:
    schedule.run_pending()
    time.sleep(1)
Output:
Custom Time:2021-05-01 17:30:29.431717 Current Time: 2021-05-04 02:06:31.249154 Time Difference: -3 days, 15:23:58.182563 Custom Time:2021-05-01 17:30:29.431717 Current Time: 2021-05-04 02:07:31.312671 Time Difference: -3 days, 15:22:58.119046

Actually, user should be able to run following code when he wants. So it should be independent of the function defined and run with while loop.

print(f'Custom Time:{custom_time} Current Time: {now} Time Difference: {custom_time-now}')
Reply


Messages In This Thread
RE: Schedule a task and render/ use the result of the task in any given time - by klllmmm - May-04-2021, 10:17 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Schedule exit a program at a specific time 4 am every day. chubbychub 3 411 May-17-2024, 03:45 PM
Last Post: chubbychub
  TypeError: Diagram.render() takes 1 positional argument but 2 were given sachin1361 0 385 Apr-23-2024, 06:39 AM
Last Post: sachin1361
Question Running Python script through Task Scheduler? Winfried 8 1,022 Mar-10-2024, 07:24 PM
Last Post: Winfried
  Background task Mctweed 4 595 Feb-13-2024, 11:50 PM
Last Post: Mctweed
  How can I multithread to optimize a groupby task: davisc4468 0 812 Jun-30-2023, 02:45 PM
Last Post: davisc4468
  [SOLVED] Why is this asyncio task blocking? SecureCoop 1 948 Jun-06-2023, 02:43 PM
Last Post: SecureCoop
  Start print a text after open an async task via button Nietzsche 0 805 May-15-2023, 06:52 AM
Last Post: Nietzsche
  How to timeout a task using the ThreadpoolExecutor? lowercase00 2 2,816 Feb-07-2023, 05:44 PM
Last Post: deanhystad
  add interrupt for next task kucingkembar 0 841 Oct-07-2022, 12:15 PM
Last Post: kucingkembar
  count certain task in task manager[solved] kucingkembar 2 1,265 Aug-29-2022, 05:57 PM
Last Post: kucingkembar

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020