手机
当前位置:查字典教程网 >脚本专栏 >python >python定时器使用示例分享
python定时器使用示例分享
摘要:复制代码代码如下:classSLTimer(multiprocessing.Process):#fromdatetimeimportdate...

复制代码 代码如下:

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根据距离和时长计算配速示例

python正则匹配查询港澳通行证办理进度示例分享

python计算最小优先级队列代码分享

学习python的几条建议分享

python 简易计算器程序,代码就几行

python根据经纬度计算距离示例

python创建和使用字典实例详解

Python的print用法示例

python支持断点续传的多线程下载示例

python 从远程服务器下载日志文件的程序

精品推荐
分类导航