from datetime import datetime import sched import time from time import sleep # 定义任务 def print_event(name): print(f"EVENT: {time.time()} - {name}") def periodic_task(interval): print(f"Task executed at: {datetime.now().strftime("%Y-%m-%d %H:%M:%S.%f")[:-2]}") scheduler.enter(interval, 1, periodic_task, (interval,)) # 按装订区域中的绿色按钮以运行脚本。 if __name__ == '__main__': # 初始化调度器 scheduler = sched.scheduler(time.time) scheduler.enter(0, 1, periodic_task, (0.33,)) # 每 5 秒执行一次 scheduler.run() print("===============")