python任务调度实例分析

yipeiwu_com6年前Python基础

本文实例讲述了python任务调度实现方法。分享给大家供大家参考。具体如下:

方法1:

import sched, time
import os
s = sched.scheduler(time.time, time.sleep)
#scheduler的两个参数用法复杂,可以不做任何更改
def playmusic(x):
  os.system(x)
def jobtodo():
   tmlist = [2011,8,11,22,15,0,0,0,0]
   x1=time.mktime(tmlist)
   x2=time.time()
   y=x1-x2
#计算任务到现在的时间长度
   s.enter(y, 1, playmusic, ('mplayer /home/c.mp3',))
#四个参数分别为:间隔事件、优先级(用于同时间到达的两个事件同时执行时定序)、被调用触发的函数,给他
#的参数(注意:一定要以tuple给如,如果只有一个参数就(xx,))
   s.run()
   print time.time()
jobtodo()

方法2:

import os
import time
from threading import Timer
def playmusic(x):
  os.system(x)
def jobtodo():
   tmlist = [2011,8,11,22,40,0,0,0,0]
   x1=time.mktime(tmlist)
   x2=time.time()
   y=x1-x2
   Timer(y, playmusic, ('mplayer /home/b.mp3',)).start()
jobtodo()

希望本文所述对大家的Python程序设计有所帮助。

相关文章

python学习之编写查询ip程序

python学习之编写查询ip程序

公司服务器上的ip最少的也有100多个,有时候查到一个站的Ip, 不想通过OA去查,自己就用自己最近学的python知识,结合数据库,编写了一python小程序。实现只要输入主ip就能查...

pandas修改DataFrame列名的实现方法

提出问题 存在一个名为dataset的DataFrame >>> dataset.columns Index(['age', 'job', 'marital',...

用python 实现在不确定行数情况下多行输入方法

如下所示: stopword = '' str = '' for line in iter(raw_input, stopword): str += line + '\n' pri...

Python读取YUV文件,并显示的方法

Python读取YUV格式文件,并使用opencv显示的方法 opencv可以读取的图片类型比较多,但大多是比较常见的类型,比如".jpg"和".png",但它不能直接读取YUV格式的文...

python基础教程之字典操作详解

字典dictionary 1.键值对的集合(map) 2.字典是以大括号“{}”包围的数据集合 3.字典是无序的,在字典中通过键来访问成员。 可变的,可嵌套,可以原处修改扩展等,不产生新...