【发布时间】:2017-01-02 15:05:29
【问题描述】:
我正在尝试制作一个倒数计时器来打印剩余时间,当您输入内容时,它会打印您输入的内容。我的问题是我不想等待输入,只是继续运行计时器。我的错误代码:
timer = 100
while True:
print(timer)
timer -= 1
if input('> '):
print('the output of input')
你可以说我想让计时器在后台打印时间。
【问题讨论】:
-
寻找
getch()或类似的函数 - 它不在标准库中。 -
如果你使用的是类似unix的操作系统,你可以
select([sys.stdin]),或者使用curses.getch,如果在Windows上,那就更复杂了。 -
so if
select([sys.stdin]) != ''then do x -
您也可以使用threading.Timer 对象并保持阻塞
input调用。
标签: python multithreading python-3.x python-multithreading python-asyncio