python定時器使用示例分享
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()
相關(guān)文章
Python3.5內(nèi)置模塊之time與datetime模塊用法實例分析
這篇文章主要介紹了Python3.5內(nèi)置模塊之time與datetime模塊用法,結(jié)合實例形式分析了Python3.5 time與datetime模塊日期時間相關(guān)操作技巧,需要的朋友可以參考下2019-04-04
結(jié)合Python網(wǎng)絡(luò)爬蟲做一個今日新聞小程序
本篇文章介紹了我在開發(fā)過程中遇到的一個問題,以及解決該問題的過程及思路,通讀本篇對大家的學(xué)習(xí)或工作具有一定的價值,需要的朋友可以參考下2021-09-09
Python數(shù)學(xué)建模PuLP庫線性規(guī)劃進階基于字典詳解
在大規(guī)模的規(guī)劃問題中,這樣逐個定義變量和設(shè)置模型參數(shù)非常繁瑣,效率很低。Pulp 庫提供了一種快捷方式,可以結(jié)合 Python語言的循環(huán)和容器,使用字典來創(chuàng)建問題2021-10-10

