本文整理汇总了Python中threading.Timer.sleep方法的典型用法代码示例。如果您正苦于以下问题:Python Timer.sleep方法的具体用法?Python Timer.sleep怎么用?Python Timer.sleep使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类threading.Timer
的用法示例。
在下文中一共展示了Timer.sleep方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: input_with_timeout
# 需要导入模块: from threading import Timer [as 别名]
# 或者: from threading.Timer import sleep [as 别名]
def input_with_timeout(dur, player):
#function to kill player
def killit():
os.kill(os.getpid(), signal.SIGINT)
#timer with kill function tagged onto end
t = Timer(dur/1000, killit)
#plays
player.play()
try:
#starts timer
t.start()
#awaits user input and acts based on input
keyboard = raw_input("Enter your next command...")
while 1:
if keyboard == "play":
player.play()
t.start()
elif keyboard == "pause":
player.pause()
t.sleep()
elif keyboard == "stop":
player.stop()
t.cancel()
return "stop"
elif keyboard == "next":
player.stop()
t.cancel()
return "next"
except KeyboardInterrupt:
print "Exception thrown"
pass
player.stop()
t.cancel()
print "Timer cancelled"
return