如何为输入创建定时器?

  • 本文关键字:创建 定时器 python
  • 更新时间 :
  • 英文 :


例如:

# 5 second response, if user doesn't do it in 5 seconds, then quit() 
a = input('Stack Overflow is cool')
if a == yes
print('Harold882')
else: 
print('asdf')

你怎么能做到这一点,或者只是做一个定时器?

我也试过制作不同的计时器,但它们都不起作用。

你可以这样做:

import time
from threading import Thread
answer = None
def check():
time.sleep(5)
if answer == None:
print("Too Slow")
elif answer == 'yes':
print('Harold882')
else:
print('asdf')

Thread(target = check).start()
answer = input("Stack Overflow is cool: ")

使用timethreading模块。

最新更新