python每隔N秒运行指定的函数程序,python每隔,一个类似定时器的效果,每
python每隔N秒运行指定的函数程序,python每隔,一个类似定时器的效果,每
一个类似定时器的效果,每隔指定的秒数运行指定的函数,采用线程实现,代码简单实用。
import osimport timedef print_ts(message): print "[%s] %s"%(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()), message)def run(interval, command): print_ts("-"*100) print_ts("Command %s"%command) print_ts("Starting every %s seconds."%interval) print_ts("-"*100) while True: try: # sleep for the remaining seconds of interval,http://www.sharejs.com time_remaining = interval-time.time()%interval print_ts("Sleeping until %s (%s seconds)..."%((time.ctime(time.time()+time_remaining)), time_remaining)) time.sleep(time_remaining) print_ts("Starting command.") # execute the command status = os.system(command) print_ts("-"*100) print_ts("Command status = %s."%status) except Exception, e: print eif __name__=="__main__": interval = 5 command = r"ipconfig" run(interval, command)
相关内容
- 一个python的2048简单实现,python2048,# -*- coding
- 更加高级的阶乘,高级阶乘,f = lambda x
- python实现爬图,不要再爬妹子图了,太没品了,python妹
- python实现爬图,不要再爬妹子图了,太没品了,python妹
- scrapy在采集网页时使用随机user-agent的方法,scrapyuser-
- python collection模块中几种数据结构(Counter、OrderedDict、
- word文档批量修改,word文档,#!/usr/bin/p
- BeautifulSoup模块的简单使用,beautifulsoup模块,可以通过
- 数字归一计算代码效率曲线,计算代码效率曲线,# -*-
- Python操作MySQL数据库实例,pythonmysql实例,在Windows平台上
评论关闭