python框架---->APScheduler的使用
这里介绍一下python中关于定时器的一些使用,包括原生的sche包和第三方框架APScheduler的实现。流年未亡,夏日已尽。种花的人变成了看花的人,看花的人变成了葬花的人。
python中的sche模块
python中的sch有模块提供了定时器任务的功能,在3.3版本之后sche模块里面的scheduler类在多线程的环境中是安全的。以下是一个案例
import sched, time sche = sched.scheduler(time.time, time.sleep) def print_time(a='default'):
print('From print_time', time.time(), a) def print_some_time():
print(time.time())
# 10是delay单位是毫秒, 1代表优先级
sche.enter(10, 1, print_time)
sche.enter(5, 2, print_time, argument=('positional',))
sche.enter(5, 1, print_time, kwargs={'a': 'keyword'})
sche.run()
print(time.time()) print_some_time()
运行的打印结果如下:
1511139390.598038
From print_time 1511139395.5982432 keyword
From print_time 1511139395.5982432 positional
From print_time 1511139400.5984359 default
1511139400.5984359
查看scheduler.enter的源码,可以看到它实际调用的是enterabs方法。
def enter(self, delay, priority, action, argument=(), kwargs=_sentinel):
"""A variant that specifies the time as a relative time. This is actually the more commonly used interface. """
time = self.timefunc() + delay
return self.enterabs(time, priority, action, argument, kwargs)
而对于enterabs方法的argument和kwargs的含义,官方文档的解释如下:它们可以作为action的参数,也就是上述例子中的print_time方法的参数
argument is a sequence holding the positional arguments for action. kwargs is a dictionary holding the keyword arguments for action.
APScheduler的使用
APScheduler的安装:pip install apscheduler。
一、第一个APScheduler的使用案例
每隔一秒打印出Hello World的字符。
from apscheduler.schedulers.blocking import BlockingScheduler
def my_job():
print('Hello World') sched = BlockingScheduler()
sched.add_job(my_job, 'interval', seconds=1)
sched.start()
友情链接
- 关于APScheduler的官方文档:https://apscheduler.readthedocs.io/en/latest/userguide.html
python框架---->APScheduler的使用的更多相关文章
- python 定时任务框架apscheduler
文章目录 安装 基本概念介绍 调度器的工作流程 实例1 -间隔性任务 实例2 - cron 任务 配置调度器 方法一 方法二 方法三: 启动调度器 方法一:使用默认的作业存储器: 方法二:使用数据库作 ...
- Python框架、库以及软件资源汇总
转自:http://developer.51cto.com/art/201507/483510.htm 很多来自世界各地的程序员不求回报的写代码为别人造轮子.贡献代码.开发框架.开放源代码使得分散在世 ...
- 【python】Python框架、库和软件资源大全
很多来自世界各地的程序员不求回报的写代码为别人造轮子.贡献代码.开发框架.开放源代码使得分散在世界各地的程序员们都能够贡献他们的代码与创新. Python就是这样一门受到全世界各地开源社区支持的语言. ...
- Python框架、库和软件资源大全(整理篇)
有少量修改,请访问原始链接.PythonWIn的exe安装包;http://www.lfd.uci.edu/~gohlke/pythonlibs/ 原文链接:codecloud.net/python- ...
- python 定时任务APScheduler 使用介绍
python 定时任务APScheduler 使用介绍 介绍: APScheduler的全称是Advanced Python Scheduler.它是一个轻量级的 Python 定时任务调度框架. ...
- python框架之django
python框架之django 本节内容 web框架 mvc和mtv模式 django流程和命令 django URL django views django temple django models ...
- android模拟器(genymotion)+appium+python 框架执行基本原理(目前公司自己写的)
android模拟器(genymotion)+appium+python 框架执行的基本过程: 1.Push.initDate(openid)方法 //业务数据初始化 1.1 v5db.p ...
- 10个用于Web开发的最好 Python 框架
Python 是一门动态.面向对象语言.其最初就是作为一门面向对象语言设计的,并且在后期又加入了一些更高级的特性.除了语言本身的设计目的之外,Python标准 库也是值得大家称赞的,Python甚至还 ...
- 第六篇:web之python框架之django
python框架之django python框架之django 本节内容 web框架 mvc和mtv模式 django流程和命令 django URL django views django te ...
随机推荐
- perl学习(二)正则表达式
模式分组: /fred+/会匹配freddd这样的 /(fred)+/会匹配fredfredfred这样的 /(fred)*/则会匹配abcdef任意的 圆括号同时也使得重新使用某些字符串成为可能.反 ...
- svn -- 数据备份,版本回退,版本冲突,多仓库配置
数据备份 差异存储法: 版本回退 版本冲突 原理图: 解决办法: 三种方案: 1)合理分配项目开发模块 wangcai:文章,邮件,会员 xiaoqiang:静态化,缓存,前台 2)合理分配项目开发时 ...
- ICMP Ping模版实现对客户端网络状态的监控
Zabbix使用外部命令fping处理ICMP ping的请求,fping不包含在zabbix的发行版本中,需要额外去下载安装fping程序,安装完毕之后需要zabinx_server.conf中的参 ...
- ASM - ByteCode插件下载、安装以及相关遇到的问题
http://asm.ow2.org/eclipse/index.html http://download.forge.objectweb.org/eclipse-update/ http://for ...
- C#页面前台<%%><%#%><%=%>
ASP.net前台绑定用的最多,今天小小总结一下. 1:<%#Eval("")%> 2:<%#Bind("")%> 3:<%=变量 ...
- GCT之语文细节知识
以下是在微博中看到的,大部分人都会读错的汉字,这也是历届GCT考试的前几道选择题可能会出的题库资源吧,高考的时候也大都考的这些,拿来共享给大家.一定要看哦.
- 如何获取模拟器安装的app的位置
你可以死记下地址格式, 但是一旦不同的xcode和模拟器版本改变变了地址, 又得记, 从活动管理器里其实是可以直接查看的: Launch the app in the simulator Open A ...
- go 类型转换
https://studygolang.com/articles/3400 https://studygolang.com/articles/6633
- 安装kafka集群
1解压tar包 tar -zxvf kafka_2.-.tgz 2.进入config目录 3.配置server.properties文件 # Licensed to the Apache Softwa ...
- Apache中的Order Allow,Deny用法详解
本文讲述了Apache中的Order Allow,Deny用法.分享给大家供大家参考,具体如下: Allow和Deny可以用于apache的conf文件或者.htaccess文件中(配合Directo ...