#使用内置time库
import time
def job():
print("I'm working...")
while True:
job()
time.sleep(10) # 每10秒执行一次
#使用schedule库
import schedule
import time
def job():
print("I'm working...")
schedule.every(10).seconds.do(job) # 每10秒执行一次job函数
while True:
schedule.run_pending() # 运行所有可以运行的任务
time.sleep(1) # 每秒检查一次任务是否到执行时间
# 使用apscheduler库
from apscheduler.schedulers.background import BackgroundScheduler
def job():
print("I'm working...")
scheduler = BackgroundScheduler() # 创建一个后台调度器
scheduler.add_job(job, 'interval', seconds=10) # 每10秒执行一次job函数
scheduler.start() # 启动调度器