admin管理员组文章数量:1574959
如果需要执行更复杂的任务调度,则可使用 Python 提供的 sched 模块。该模块提供了 sched.scheduler 类,该类代表一个任务调度器。
sched.scheduler(timefunc=time.monotonic, delayfunc=time.sleep) 构造器支持两个参数:
timefunc:该参数指定生成时间戳的时间函数,默认使用 time.monotonic 来生成时间戳。
delayfunc:该参数指定阻塞程序的函数,默认使用 time.sleep 函数来阻塞程序。
sched.scheduler 调度器支持如下常用属性和方法:
scheduler.enterabs(time, priority, action, argument=(), kwargs={}):指定在 time 时间点执行 action 函数,argument 和 kwargs 都用于向 action 函数传入参数,其中 argument 使用位置参数的形式传入参数,kwargs 使用关键字参数的形式传入参数。该方法返回一个 event,它可作为 cancel() 方法的参数用于取消该调度。priority 参数指定该任务的优先级,当在同一个时间点有多个任务需要执行时,优先级高(值越小代表优先级越高)的任务会优先执行。
1.scheduler.enter(delay, priority, action, argument=(),kwargs={}):该方法与上一个方法基本相同,只是 delay 参数用于指定多少秒之后执行 action 任务。
2.scheduler.cancel(event):取消任务。如果传入的 event 参数不是当前调度队列中的 event,
版权声明:本文标题:python schedule多线程_schedule任务调度及其用法(多线程并发) 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://www.elefans.com/dianzi/1725781644a1042259.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论