#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. 一、Android屏幕的计量单位

    px  :是屏幕的像素点in   :英寸mm:毫米pt   :磅,1/72英寸dp  :一个基于density的抽象单位,如果一个160dpi的屏幕,1dp=1pxdip :等同于dpsp  :同dp ...

  2. CxImage图像库的使用 .

    http://blog.csdn.net/wangjie0377/article/details/7830405 CxImage图像库 CxImage下载地址:http://www.codeproje ...

  3. Java—从文件中读取数据

    1.FileInputStream() // 构建字节输入流对象,参数为文件名 FileInputStream fin = new FileInputStream("message" ...

  4. viewBox A-Z滚动样式

    效果图:       代码实现 (其中使用了ionic框架...) html 代码: <ion-content class='page-location'> <div class=' ...

  5. php性能优化实用技巧:

    以下是五个优化技巧,熟练掌握后对于开发还是很有帮助的. 1. 对字符串使用单引号 PHP 引擎允许使用单引号和双引号来封装字符串变量,但是这个是有很大的差别的!使用双引号的字符串告诉 PHP 引擎首先 ...

  6. Linux上安装oracle客户端及sqlldr

    1.建立oracle的安装目录,一般为/opt/oracle:2.将安装包instantclient-basic-linux.x64-11.2.0.3.0.zip放入到该目录中,并进行解压:unzip ...

  7. Android 学习第16课,java 包、类等相关的一些基础知识

    1.建议将类放在包中,不要使用无名包 2.建议包名都用小写单词组成,不要用大写 3.建议包名用“域名的倒写.项目名.模块名”的形式,以确保包名的唯一性 注意:类变量与实例变量.类方法与实例方法的区别 ...

  8. B - I Hate It

    #include<cstdio> #include<string.h> using namespace std; int ans; ; ]; struct Node{ int ...

  9. C语言指针,你还觉得难吗?

    在研究式学习-c语言程序设计指针式这样介绍的: 内存中存储变量的第一个单元的地址 称为指针,存放指针的变量称为指针变量: 变量的访问方式有: 直接访问方式:按变量名查找其首地址 间接访问方式:通过指针 ...

  10. VLOOKUP

    vlookup(查找目标,查找范围, 返回值的列数,精确或模糊查找) 1. 查找目标:查找的内容或者单元格引用. 2. 查找范围: 选定一个查找区域. 注意一: 查找目标一定要在该区域的第一列. 注意 ...