我正在使用windows和python 3.8。我想向python脚本发送额外的输入,我也希望输入超时。
我尝试了以下几点:
import sys, select
print("You have 5 seconds to answer")
i, o, e = select.select([sys.stdin], [], [], 5)
if (i):
print("You said", sys.stdin.readline().strip())
else:
print("You said nothing")
这导致了一个错误:
i,o,e= select.select(sys.stdin,[],[],5) OSError: WinError 10038尝试对非套接字的东西执行操作
如何获得输入工作的超时时间?
发布于 2022-06-13 20:00:04
我找到的解决办法是:
$ pip安装输入超时
from inputimeout import inputimeout, TimeoutOccurred
try:
something = inputimeout(prompt='>>', timeout=10)
except TimeoutOccurred:
something = 'Time is up'
print(something)
https://stackoverflow.com/questions/72607369
复制相似问题