Python Task Scheduling Example analysis

Source: Internet
Author: User
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.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.