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 = datetime.now().__str__()[:10]
else :
_date = date
_time = ''
time が 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 '眠っています... %s ' % now
time.sleep(1.0)
super(SLTimer,self).run()
测试
def t23():
from stock.task import SLTimer
timer = SLTimer(show1, time='16:31:50')
timer.start()