为什么SIGINT会导致诅咒getkey抱怨“无输入”?

时间:2020-10-17 12:07:23

标签: python debian python-curses debian-stretch

重现:在阻塞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

0 个答案:

没有答案