SoFunction
Updated on 2024-12-19

Example analysis of python task scheduling

This article example describes the python task scheduling implementation. Shared for your reference. Specific as follows:

Method 1.

import sched, time
import os
s = (, )
The two parameters of #scheduler are complex and can be left unchanged.
def playmusic(x):
  (x)
def jobtodo():
   tmlist = [2011,8,11,22,15,0,0,0,0]
   x1=(tmlist)
   x2=()
   y=x1-x2
# Calculate the length of time the task has taken until now
   (y, 1, playmusic, ('mplayer /home/c.mp3',))
#The four parameters are: the interval event, the priority (for sequencing when two events arriving at the same time are executed at the same time), and the function that is called to trigger it, giving him the
# of parameters (note: must give as in tuple, if only one parameter then (xx,))
   ()
   print ()
jobtodo()

Method 2:

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

I hope that what I have said in this article will help you in your Python programming.