This article mainly introduces the python task scheduling implementation method. The example analyzes the Task Scheduling Principle and Python implementation method. If you need it, refer to the following example to describe the python task scheduling implementation method. Share it with you for your reference. The details are as follows:
Method 1:
Import sched, timeimport oss = sched. scheduler (time. time, time. sleep) # The usage of the two schedmusic parameters is complex. def playmusic (x): OS. system (x) def jobtodo (): tmlist = [, 0] x1 = time. mktime (tmlist) x2 = time. time () y = x1-x2 # The length of time s from the computing task to the present. enter (y, 1, playmusic, ('mplayer/home/c.mp3 ',) # The four parameters are: interval event, priority (used to execute the sequence of two events at the same time), the function triggered by the call, and the parameter # (Note: it must be given to tuple, for example, if there is only one parameter (xx,) s. run () print time. time () jobtodo ()
Method 2:
Import osimport timefrom threading import Timerdef playmusic (x): OS. system (x) def jobtodo (): tmlist = [, 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 Python programming.