Python定時任務sched(一)

2021-08-20 02:40:23 字數 1317 閱讀 5358

這裡介紹一下python中定時任務:sched

import datetime

import schedule

import time

import sched

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

def

fun2(string1):

# time.sleep(10)

print("now is ",time.time(),

"====",string1,

"==string2=")

def

fun3(string1):

# time.sleep(10)

print("now is ",time.time(),

"====",string1,

"==fun3=")

def

fun4(string1):

# time.sleep(10)

print("now is ",time.time(),

"====",string1,

"==fun4=")

def

run2():

# print(1)

# enter之後可帶的引數意義:delay, priority, action, argument=()

# delay表示執行週期,也就是多久之後開始執行

# priority表示執行優先等級,1~10的優先順序排序,1為最先執行者

# action執行的函式名

# argument表示函式帶的引數,以{}形式封裝

schedule2.enter(1, 1

, fun2,)

schedule2.enter(1, 2

, fun2,)

schedule2.enter(1, 3

, fun2,)

schedule2.enter(1, 4

, fun3, )

schedule2.enter(1, 5

, fun4, )

schedule2.enter(1, 6

, fun3, )

schedule2.enter(1, 7

, fun4, )

schedule2.run()

python定時任務 sched模組

通過sched模組可以實現通過自定義時間,自定義函式,自定義優先順序來執行函式。範例一1 import time 2import sched 34 schedule sched.scheduler time.time,time.sleep 56 deffunc string1 7print now ...

python定時任務 sched模組

通過sched模組可以實現通過自定義時間,自定義函式,自定義優先順序來執行函式。schedule sched.scheduler time.time,time.sleep schedule是乙個物件,叫什麼名字都可以。schedule.enter delay,priority,action,argu...

springboot之定時任務 Scheduled

1 pom.xml中匯入必要的依賴 org.springframework.boot spring boot starter parent 2.0.1.release org.springframework.boot spring boot starter web org.springframewo...