
这是一个半屁股解决方案,它不考虑时钟抖动或时钟调整。请参阅注释以了解解决方法。
import timeimport datetime# if for some reason this script is still running# after a year, we'll stop after 365 daysfor i in xrange(0,365): # sleep until 2AM t = datetime.datetime.today() future = datetime.datetime(t.year,t.month,t.day,2,0) if t.hour >= 2: future += datetime.timedelta(days=1) time.sleep((future-t).total_seconds()) # do 2AM stuff
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)