python定时器使用示例分享
2014-02-16 00:00
796 查看
class SLTimer(multiprocessing.Process): #from datetime import datetime #import time def __init__(self, target=None, args=(), kwargs={},date=None,time=None): '''\ @param date 1900-01-01 @param time 00:00:00 ''' super(SLTimer,self).__init__(target=target,args=args,kwargs=kwargs) _date = '' if date is None: _date = datetime.now().__str__()[:10] else : _date = date _time = '' if time is None: _time = datetime.now().__str__()[11:19] else: _time = time self.__runtime = '%s %s' % (_date,_time) def run(self): timeLen = len('1900-00-00 00:00:00') while True: now = datetime.now().__str__()[:timeLen] if now>=self.__runtime: break print 'sleeping... %s' % now time.sleep(1.0) super(SLTimer,self).run()
测试
def show1(): from datetime import datetime print 'hello,current time:%s' % datetime.now().__str__() def t23(): from stock.task import SLTimer timer = SLTimer(show1, time='16:31:50') timer.start()
相关文章推荐
- python定时器使用示例分享
- python使用cookielib库示例分享
- python使用cookielib库示例分享
- 使用python解析xml成对应的html示例分享
- python文件读写并使用mysql批量插入示例分享(python操作mysql)
- 两个使用Python脚本操作文件的小示例分享
- python使用PyV8执行javascript代码示例分享
- python列表操作使用示例分享
- 使用python统计文件行数示例分享
- python使用PyV8执行javascript代码示例分享
- 使用python解析xml成对应的html示例分享
- 使用Python生成随机密码的示例分享
- 使用Python生成随机密码的示例分享
- python使用cookielib库示例分享
- 使用python统计文件行数示例分享
- python列表操作使用示例分享
- 两个使用Python脚本操作文件的小示例分享
- python文件读写并使用mysql批量插入示例分享(python操作mysql)
- Python使用PyCrypto实现AES加密功能示例
- Python的collections模块中namedtuple结构使用示例