Analysis of python task scheduling instances

Source: Internet
Author: User

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.

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.