python sched

__author__ = 'Administrator'

# -*- coding: utf-8 -*-

#! /usr/bin/env python

#coding=utf-8

#這裏需要引入三個模塊

import time, os, sched,threading


# 第一個參數確定任務的時間,返回從某個特定的時間到現在經歷的秒數

# 第二個參數以某種人爲的方式衡量時間

schedule = sched.scheduler(time.time, time.sleep)


def perform_command(cmd, inc):

    os.system(cmd)


def timming_exe(cmd, inc = 60):

    # enter用來安排某事件的發生時間,從現在起第n秒開始啓動

    schedule.enter(inc, 0, perform_command, (cmd, inc))

    schedule.enter(10, 0, perform_command, (cmd, inc))

    schedule.enter(3, 0, perform_command, (cmd, inc))

    # 持續運行,直到計劃時間隊列變成空爲止

    t = threading.Thread(target=schedule.run)

    #schedule.run()

    t.start()



print("show time after 10 seconds:")

timming_exe("echo %time%", 5)

print "next"


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章