This paper describes the implementation method of Python task scheduling. Share to everyone for your reference. Specific as follows:
Method 1:
Import sched, Timeimport oss = Sched.scheduler (time.time, Time.sleep) #scheduler的两个参数用法复杂, 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# calculates the task to the current length of time s.enter (y, 1, Playmusic, (' Mplayer/home/c.mp3 ',)) #四个参数分别为: Interval events, Priority (for simultaneous execution of two events at the same time), called Trigger function, give him # parameters (Note: Must be given as a tuple, if there is only one argument (xx,)) S.run () print time.time () Jobtodo ()
Method 2:
Import osimport timefrom Threading Import Timerdef 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 ()
Hopefully this article will help you with Python programming.