Python(14):定时执行一段任务

来源:互联网 发布:手机端js弹出软键盘 编辑:程序博客网 时间:2024/06/06 12:31

while 1 就可以了。要注意sleep。不然CPU就……

# -*- coding: utf-8 -*-"""Created on Sat Jun 10 22:03:44 2017@author: qcy"""import datetimeimport timesched_time = '2017/06/10 22:19:20' # 这里填启动的时间while 1:        # str(datetime.datetime.now())[0:19]            now_str = datetime.datetime.now().strftime('%Y/%m/%d %H:%M:%S')    print(sched_time, ' ', now_str)    if now_str == sched_time:        print('T=5s, exec...',now_str)    else:        print('sleep 1s')        time.sleep(1)

原创粉丝点击