003_011 Python 执行定时任务 在某个时刻执行该任务
2014-03-26 00:02
218 查看
代码如下:
打印结果如下:
中国
2014,3,23
1395764390.49
Hello World
2014,3,23
1395764400.54
#encoding=utf-8 print '中国' #执行定时任务 在某个时刻执行该任务 import time, os, sys, sched #执行计划 第一个参数要执行的时间,第二个参数用来等待一段时间 schedule=sched.scheduler(time.time, time.sleep) def perform_command(cmd, inc): #enter 延迟时间 优先级 回调函数 参数 os.system(cmd) print '' print time.time() schedule.enter(inc, 0, perform_command, (cmd,inc)) def CirculeGo(cmd, inc=60): schedule.enter(0, 0, perform_command, (cmd,inc)) schedule.run() #1、打开 https://pypi.python.org/pypi/APScheduler/2.1.2 #2、下载 https://pypi.python.org/pypi?:action=show_md5&digest=6862959d460c16ef325d63e1fc3a6684 #3、解压APScheduler-2.1.2.tar.gz #4、cmd进入该目录,执行setup.py install from apscheduler.scheduler import Scheduler sched = Scheduler() sched.daemonic = False def job_function(text): print text from datetime import datetime #在某个时刻执行该任务 job = sched.add_date_job(job_function, datetime(2014, 03, 26, 00, 20, 00), ['Hello World']) sched.start() CirculeGo('type d:\\123.txt',10)
打印结果如下:
中国
2014,3,23
1395764390.49
Hello World
2014,3,23
1395764400.54
相关文章推荐
- 003_010 Python 重复执行任务,即定时任务
- 【Python】django-celery执行定时任务
- window设置定时任务执行python脚本
- Python 定时执行线程 执行任务
- Python脚本在crontab定时任务中无法运行,但是对应脚本手动执行成功
- python django执行定时任务
- Python自动运维系列:每天凌晨定时执行特定任务
- windows下python设置定时任务(定时执行脚本)
- Python开发【笔记】:单线程下执行多个定时任务
- python-定时执行任务(转)
- python 触发器!利用触发器定时执行某项任务!
- crontab定时任务中不能执行python shell命令
- python设置定时任务(定时执行脚本)
- python定时执行nutch爬取任务
- Python定时执行某个任务
- 深入学习python (六) 用sched来定时执行任务
- Python 以一个指定的间隔定时循环执行任务
- Python定时执行任务
- Python(14):定时执行一段任务
- python<win10下使用定时任务执行程序>