【python】python定时器
#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定时器的更多相关文章
- python线程定时器Timer(32)
相对前面几篇python线程内容而言,本片内容相对比较简单,定时器 – 顾名思义,必然用于定时任务. 一.线程定时器Timer原理 原理比较简单,指定时间间隔后启动线程!适用场景:完成定时任务,例如: ...
- python --- Python中的callable 函数
python --- Python中的callable 函数 转自: http://archive.cnblogs.com/a/1798319/ Python中的callable 函数 callabl ...
- Micro Python - Python for microcontrollers
Micro Python - Python for microcontrollers MicroPython
- 从Scratch到Python——python turtle 一种比pygame更加简洁的实现
从Scratch到Python--python turtle 一种比pygame更加简洁的实现 现在很多学校都开设了Scratch课程,学生可以利用Scratch创作丰富的作品,然而Scratch之后 ...
- 从Scratch到Python——Python生成二维码
# Python利用pyqrcode模块生成二维码 import pyqrcode import sys number = pyqrcode.create('从Scratch到Python--Pyth ...
- [Python]Python 使用 for 循环的小例子
[Python]Python 使用 for 循环的小例子: In [7]: for i in range(5): ...: print "xxxx" ...: print &quo ...
- [python]python 遍历一个list 的小例子:
[python]python 遍历一个list 的小例子: mlist=["aaa","bbb","ccc"]for ss in enume ...
- [Python]Python日期格式和字符串格式相互转换
由字符串格式转化为日期格式的函数为: datetime.datetime.strptime() 由日期格式转化为字符串格式的函数为: datetime.datetime.strftime() # en ...
- [python]Python 字典(Dictionary) update()方法
update() 函数把字典dict2的键/值对更新到dict里.如果后面的键有重复的会覆盖前面的语法dict.update(dict2) dict = {'Name': 'Zara', 'Age': ...
- Python 之定时器
#引入库 threading import threading #定义函数 def fun_timer(): print('hello timer') #打印输出 global timer #定 ...
随机推荐
- 【杂】孔明锁6根解法 & 九连环的拆卸方法及还原
**************************** Part1: 孔明锁6根解法: **************************** 第一步,编号: 第二步,按照编号组装: 第三步,完成 ...
- alpha值的问题
但凡图像都会涉及到透明度问题.使用透明度之后就可以看到多层图像.Alpha值就是用于描述透明度的参量.Alpha值是一个百分数,alpha=1表示源文件发出的光全部被观察者观察到. 既然是透明度,那么 ...
- NPOI 数据导入导出
{ //数据导入 OpenFileDialog open = new OpenFileDialog(); open.Filter = "Excle文件|*.xls"; open.T ...
- Why jsp?
Before the JSP come into the world . The CGI and servlet took the responsibility of generating dynam ...
- UE4 通过HTTP 接受JPG并动态 构建 UTexture2D 简单例子
s void UChildBaseUserWidget::setTextureFromLoadImg(FHttpRequestPtr _request, FHttpResponsePtr _respo ...
- HTML5+ 拍照上传 和选择文件上传
HTML 页面内容包含以下标签即可: <input id="btn_select" type="button" value="从相册选择&quo ...
- 对字符串进行简单的字符数字统计 探索java中的List功能
题目: 统计一个字符串中数字和字符串的个数,并分别进行排列,要求 1.数字,字符串可以从键盘获取. 2.储存在list 3.统计数字个数,字符串个数 4.把数字和字符串按从小到大的顺序输出 5.不能使 ...
- Ansible-Tower快速入门-5.导入许可【翻译】
导入许可 Tower需要一个有效的许可才可以正常运行,当你输入你的相关信息得以下载tower时,你应该有接收到一封包含许可的email邮件,你也可以直接从ansible获取许可. 如果你不能获取许可或 ...
- IOS开发官方文档随笔
马上着手开发IOS应用程序 创建第一个单视图应用 ###main 方法 int main(int argc, char * argv[]) { @autoreleasepool { return UI ...
- Html中代码换行造成空格间距的问题
Html中代码换行造成空格间距的问题解析 解决方法: 一.简单粗爆不换行 写代码的时候不要换行,input等在一行输写,那么将解决该问题.但是代码就变得不再那么容易好看. 二.设置父级块的字体大小为0 ...