python的schedule 模块用法示例
2017-01-05 12:07
676 查看
#! /usr/bin/env python
#coding=utf-8
import time, os, sched
# 第一个参数确定任务的时间,返回从某个特定的时间到现在经历的秒数
# 第二个参数以某种人为的方式衡量时间
schedule = sched.scheduler(time.time, time.sleep)
def perform_command(cmd, inc):
# os.system(cmd)
print(time.time())
print('zhixing写入数据库',time.time() -tt)
global tt
tt=time.time()
def timming_exe(cmd, inc = 60):
# enter用来安排某事件的发生时间,从现在起第n秒开始启动
schedule.enter(inc, 0, perform_command, (cmd, inc))
# # 持续运行,直到计划时间队列变成空为止
schedule.run()
if __name__ == '__main__':
tt=time.time()
print("show time after 5 seconds:",tt)
timming_exe("echo %time%", 5)
2、利用sched实现周期调用
[python] view
plain copy
#! /usr/bin/env python
#coding=utf-8
import time, os, sched
# 第一个参数确定任务的时间,返回从某个特定的时间到现在经历的秒数
# 第二个参数以某种人为的方式衡量时间
schedule = sched.scheduler(time.time, time.sleep)
def perform_command(cmd, inc):
# 安排inc秒后再次运行自己,即周期运行
schedule.enter(inc, 0, perform_command, (cmd, inc))
# os.system(cmd)
print(time.time())
print('zhixing写入数据库',time.time() -tt)
global tt
tt=time.time()
def timming_exe(cmd, inc = 60):
# enter用来安排某事件的发生时间,从现在起第n秒开始启动
schedule.enter(inc, 0, perform_command, (cmd, inc))
# # 持续运行,直到计划时间队列变成空为止
schedule.run()
if __name__ == '__main__':
tt=time.time()
print("show time after 5 seconds:",tt)
timming_exe("echo %time%", 5)
#coding=utf-8
import time, os, sched
# 第一个参数确定任务的时间,返回从某个特定的时间到现在经历的秒数
# 第二个参数以某种人为的方式衡量时间
schedule = sched.scheduler(time.time, time.sleep)
def perform_command(cmd, inc):
# os.system(cmd)
print(time.time())
print('zhixing写入数据库',time.time() -tt)
global tt
tt=time.time()
def timming_exe(cmd, inc = 60):
# enter用来安排某事件的发生时间,从现在起第n秒开始启动
schedule.enter(inc, 0, perform_command, (cmd, inc))
# # 持续运行,直到计划时间队列变成空为止
schedule.run()
if __name__ == '__main__':
tt=time.time()
print("show time after 5 seconds:",tt)
timming_exe("echo %time%", 5)
2、利用sched实现周期调用
[python] view
plain copy
#! /usr/bin/env python
#coding=utf-8
import time, os, sched
# 第一个参数确定任务的时间,返回从某个特定的时间到现在经历的秒数
# 第二个参数以某种人为的方式衡量时间
schedule = sched.scheduler(time.time, time.sleep)
def perform_command(cmd, inc):
# 安排inc秒后再次运行自己,即周期运行
schedule.enter(inc, 0, perform_command, (cmd, inc))
# os.system(cmd)
print(time.time())
print('zhixing写入数据库',time.time() -tt)
global tt
tt=time.time()
def timming_exe(cmd, inc = 60):
# enter用来安排某事件的发生时间,从现在起第n秒开始启动
schedule.enter(inc, 0, perform_command, (cmd, inc))
# # 持续运行,直到计划时间队列变成空为止
schedule.run()
if __name__ == '__main__':
tt=time.time()
print("show time after 5 seconds:",tt)
timming_exe("echo %time%", 5)
相关文章推荐
- python的schedule 模块用法示例
- Python中time模块和datetime模块的用法示例
- Python logging模块用法示例
- Python中time模块和datetime模块的用法示例
- Python pymongo模块用法示例
- Python中shutil模块的常用文件操作函数用法示例
- Python定时任务sched模块用法示例
- Python中shutil模块的常用文件操作函数用法示例
- Python pygorithm模块用法示例【常见算法测试】
- python os模块的主要用法
- python 日志模块示例的详细分析
- python logging 模块完整使用示例
- python的urllib模块显示下载进度示例
- python os模块的主要用法
- python模块:win32com用法详解
- python pipe模块用法
- 树莓派中python获取GY-85九轴模块信息示例
- python中计时工具timeit模块的基本用法 分类: python python基础学习 2013-08-08 10:05 2072人阅读 评论(0) 收藏
- python模块:win32com用法详解
- python模块:win32com用法详解