Analysis of python task scheduling instances
This example describes how to implement python task scheduling. Share it with you for your reference. The details are as follows:
Method 1:
?
| 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. schedep (time. time, time. sleep) # The usage of the two scheduler parameters is complex and can be left unchanged. Def playmusic (x ): OS. system (x) Def jobtodo (): Tmlist = [, 0] X1 = time. mktime (tmlist) X2 = time. time () Y = x1-x2 # Duration of computing task till now S. enter (y, 1, playmusic, ('mplayer/home/c.mp3 ',)) # The four parameters are: interval event, priority (used for the simultaneous execution of two events at the same time), and The called triggered function. # Parameters (Note: tuple must be used for example, if there is only one parameter (xx ,)) S. run () Print time. time () Jobtodo () |
Method 2:
?
| 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 = [, 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.