0
Follow
0
View

Print sched queue with human readable time

dqswllove 注册会员
2023-01-25 21:03

I haven't changed anything, apart from adding the actual jobs, and this seems to work fine.

import sched
from time import datetime
import time

scheduler = sched.scheduler(timefunc=time.time)

def main():
    """Do the main thing"""
    time.sleep(3)
    print('Done main')

def other():
    """Do the other thing"""
    time.sleep(2)
    print('Done other')

scheduler.enter(3, 2, main)
scheduler.enter(2, 1, other)

def executing_at_message(event):
    date = datetime.fromtimestamp(event.time)
    print(f"{date.hour}:{date.minute}:{date.second} {event.action.__doc__}")

for event in scheduler.queue:
    executing_at_message(event)

output:

22:41:45 Do the other thing
22:41:46 Do the main thing

About the Author

Question Info

Publish Time
2023-01-25 21:03
Update Time
2023-01-25 21:03

Related Question