#coding:utf-8
import os
import time def print_ts(message):
print "[%s] %s"%(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()), message)###转为为2016-09-08 13:36:32时间格式 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
print_ts("Sleeping until %s (%s seconds)..."%((time.ctime(time.time()+interval)), interval))
time.sleep(interval)
print_ts("Starting command.") # execute the command
status = os.system(command)
print_ts("-"*100)
print_ts("Command status = %s."%status)
except Exception,e:
print e if __name__=="__main__":
interval = 500
command = r"ipconfig"
run(interval, command)

  

【python】python定时器的更多相关文章

  1. python线程定时器Timer(32)

    相对前面几篇python线程内容而言,本片内容相对比较简单,定时器 – 顾名思义,必然用于定时任务. 一.线程定时器Timer原理 原理比较简单,指定时间间隔后启动线程!适用场景:完成定时任务,例如: ...

  2. python --- Python中的callable 函数

    python --- Python中的callable 函数 转自: http://archive.cnblogs.com/a/1798319/ Python中的callable 函数 callabl ...

  3. Micro Python - Python for microcontrollers

    Micro Python - Python for microcontrollers MicroPython

  4. 从Scratch到Python——python turtle 一种比pygame更加简洁的实现

    从Scratch到Python--python turtle 一种比pygame更加简洁的实现 现在很多学校都开设了Scratch课程,学生可以利用Scratch创作丰富的作品,然而Scratch之后 ...

  5. 从Scratch到Python——Python生成二维码

    # Python利用pyqrcode模块生成二维码 import pyqrcode import sys number = pyqrcode.create('从Scratch到Python--Pyth ...

  6. [Python]Python 使用 for 循环的小例子

    [Python]Python 使用 for 循环的小例子: In [7]: for i in range(5): ...: print "xxxx" ...: print &quo ...

  7. [python]python 遍历一个list 的小例子:

    [python]python 遍历一个list 的小例子: mlist=["aaa","bbb","ccc"]for ss in enume ...

  8. [Python]Python日期格式和字符串格式相互转换

    由字符串格式转化为日期格式的函数为: datetime.datetime.strptime() 由日期格式转化为字符串格式的函数为: datetime.datetime.strftime() # en ...

  9. [python]Python 字典(Dictionary) update()方法

    update() 函数把字典dict2的键/值对更新到dict里.如果后面的键有重复的会覆盖前面的语法dict.update(dict2) dict = {'Name': 'Zara', 'Age': ...

  10. Python 之定时器

    #引入库 threading import threading #定义函数 def fun_timer(): print('hello timer')   #打印输出 global timer  #定 ...

随机推荐

  1. STL库中的正态分布函数

    在设计抽奖一类程序中,有时会需要一种概率“有较大可能获得一个普通结果,有较小可能获得一个糟糕或极好的结果”,这就可以用正态分布函数来获得这样一个结果. STL中已经提供了一系列随机分布的函数,包括正态 ...

  2. Android实现Layout缩放动画

    最近看到Any.do的缩放效果很酷,看到一篇讲Layout缩放动画实现的文章,记录一下: http://edison-cool911.iteye.com/blog/704812

  3. sudo apt-get install apache2 php7.0 php7.0-mysql mysql-server

    sudo apt-get install apache2 php7.0 php7.0-mysql mysql-server sudo apt-get install libapache2-mod-ph ...

  4. python 新旧类的问题

    老式类就是经典类,不是继承自object类.在多继承时采用深度优先遍历父类.新式类就是基类继承自object类 class xxx(object).多继承时采用一种新的C3 算法来遍历父类.实例如下: ...

  5. linux 下 C语言显示中文

    例如:tset.c int main() { printf("你好,世界\n"); retuen 0; } 编译时应该这样: iconv -f gb2312 -t utf8 tes ...

  6. @html.ActionLink的几种参数格式

    一 Html.ActionLink("linkText","actionName") 该重载的第一个参数是该链接要显示的文字,第二个参数是对应的控制器的方法, ...

  7. pb将datawindow数据导出EXCEL

    PB有dw有自带功能可以将数据导出成excel,但是head却是字段名称,这样不直观. 所见即所得的方式是,将dw保存成html然后将后缀名改成xls,但这样的方式还有些问题就是会错列,解决的方法是将 ...

  8. ListView只允许展开其中一个item的方法

    xml文件代码: <?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:an ...

  9. 接口 Post

    public static StringBuilder HttpPost(string Url, byte[] Postdata, string i) { StringBuilder content ...

  10. CodeForces 239 Long Path

    每个房间有两个单向出口,就是只能进不能出,这个开始理解错了. 进入房间的时候,首先要在屋顶画一个叉叉,如果画完之后叉叉的个数是奇数的话:那么就从第二条出口出去,会到达p[ i ]房间:如果叉叉的个数是 ...