import sched import time, arrow def timedTask(): scheduler = sched.scheduler(time.time, time.sleep) scheduler.enter(10, 1, task) scheduler.run() # 每10秒执行一次 def task(): print(arrow.now().format('YYYY-MM-DD HH:ss')) while True: timedTask()
import sched import time, arrow def timedTask(): scheduler = sched.scheduler(time.time, time.sleep) scheduler.enter(10, 1, task) scheduler.run() # 每10秒执行一次 def task(): print(arrow.now().format('YYYY-MM-DD HH:ss')) while True: timedTask()