本文整理汇总了Python中clock.Clock.hourstostate方法的典型用法代码示例。如果您正苦于以下问题:Python Clock.hourstostate方法的具体用法?Python Clock.hourstostate怎么用?Python Clock.hourstostate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类clock.Clock
的用法示例。
在下文中一共展示了Clock.hourstostate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: clockinit
# 需要导入模块: from clock import Clock [as 别名]
# 或者: from clock.Clock import hourstostate [as 别名]
help='comfort step interval when waiting',
default=10, type=pos_int)
args = parser.parse_args()
if args.step > args.comfortstep:
args.comfortstep = args.step
clock, statestore, nvramstore = clockinit(args)
def usr1handler(signum, frame):
clock.state -= 2
signal.signal(signal.SIGUSR1, usr1handler)
try:
while True:
now = time.time()
nows = time.localtime(now)
nowstate = Clock.hourstostate(nows.tm_hour, nows.tm_min,
nows.tm_sec) + now % 1
if (nowstate // args.step) == (clock.state // args.step):
time.sleep(args.step - nowstate % args.step)
else:
towait = clock.timetowait(nowstate, args.comfortstep) \
+ args.step - nowstate % args.step
if clock.timetogo(nowstate) > towait:
# waiting for the time with comfort step every few seconds
time.sleep(args.comfortstep - nowstate % args.comfortstep
if towait > args.comfortstep > 1
else towait)
clock.step()
nvramstore.save()
finally:
statestore.save()