#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. jQuery的常见操作

    1.  选择符: a)          a > b 作为a子元素的b匹配的元素 b)         a + b 作为后面直接同辈元素的b匹配的元素 c)         a ~ b 作为后面 ...

  2. LayaAir引擎——(二)

    LayaAir引擎 -> 工具 -> 图集打包例子

  3. 【转】Xcode概览:调试应用程序

    原文转自:http://www.cocoachina.com/ios/20141128/10358.html 本文由CocoaChina翻译组成员Creolophus(github主页)翻译自苹果官方 ...

  4. PythonS12-day4学习笔记

    # 迭代器.装饰器.生成器 # 迭代器 li = [1, 3, 'he', '&'] n = iter(li) print(n.__next__()) import os, sys # 生成器 ...

  5. Unity3D-ScrollRect 各参数的代码引用以及作用

    版本Unity4.6: 以下为ScrollRect面板上各选项 对应 在代码里的属性: content(RectTransform): scrollRect的RectTransform组件,即滑动面板 ...

  6. 【JS】IE兼容placeholder

    直接上代码: $(document).ready(function () { var doc = document, textareas = doc.getElementsByTagName('tex ...

  7. python数据结构

      . 数据结构¶ .1. 深入列表¶ 链表类型有很多方法,这里是链表类型的所有方法: list.append(x) 把一个元素添加到链表的结尾,相当于 a[len(a):] = [x] . list ...

  8. Pixel VS Point, FrameBuffer VS RenderBuffer

    // How iOS app MVC works View, Window, AppDelegate ViewController, RootViewController // On Pixel VS ...

  9. MyBatis笔记

    Mybatis:将java对象映射成SQL语句,再将结果转化为java对象,解决了java对象和sql拼接.结果集的问题,又可以自己写sql语句 总体结构: 根据JDBC规范建立与数据库的连接 通过反 ...

  10. js实现图片实时预览

    注: 此博客转自 http://www.cnblogs.com/goody9807/p/6064582.html  转载请注明出处 <body> 上传图片: <input type= ...