import sched,time

def loopTask():
    print('定时任务执行')


count = 0
loopcount = 5
# 定义一个函数,用于在调度器中反复添加任务  
def add_task_repeatedly(a_sched, interval, function, argument=()):
    a_sched.enter(interval, 1, add_task_repeatedly, argument=(a_sched, interval, function, argument))  
    function(*argument)  
    # global count,loopcount    
    # print(type(count),type(loopcount),loopcount)  
    # if count <  loopcount:    
    #     count  += 1   
        
    # else:
    #     return True


s = sched.scheduler(time.time, time.sleep)
add_task_repeatedly(s, 5, loopTask)
s.run()