Analysis of python task scheduling instances

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

Related Article

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.