问题描述
重现:在阻塞getkey函数时,按 CTRL + C 或pkill
将SIGINT发送到此程序。
我认为这可能与缓冲区有关,因此我在python-curses documentation中搜索“缓冲区”。
我仍然不明白“无输入”问题的原因是什么。
#!/usr/bin/python3
import curses
import os
count=0
def main(win):
key=""
#flushinp solved the "no input" problem but I can't understand what is the reason of the problem
#curses.flushinp()
win.clear()
win.addstr("Detected key:")
win.addstr("\ncount:{}".format(count))
while 1:
key = win.getkey()
win.clear()
win.addstr("Detected key:")
win.addstr(str(key))
win.addstr("\ncount:{}".format(count))
if key == os.linesep:
quit()
while 1:
try:
curses.wrapper(main)
except KeyboardInterrupt:
count+=1
continue
$ ./test.py
Traceback (most recent call last):
File "./test.py",line 22,in <module>
curses.wrapper(main)
File "/usr/lib/python3.5/curses/__init__.py",line 94,in wrapper
return func(stdscr,*args,**kwds)
File "./test.py",line 13,in main
key = win.getkey()
_curses.error: no input
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)