This paper illustrates the implementation method of Python task scheduling. Share to everyone for your reference. Specifically as follows:
|1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17-18||Import sched, time import os s = Sched.scheduler (Time.time, Time.sleep) #scheduler的两个参数用法复杂, you can make no changes to 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 ',)) #四个参数分别为: Interval event, priority (for the simultaneous execution of two events at the same time), invoked function, and give him Parameter (Note: Be sure to give as tuple, if only one argument is (XX,)) S.run () print time.time () Jobtodo ()|
|1 2 3 4 5 6 7 8 9 10 11-12||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 ()|
I hope this article will help you with your Python programming.