Question

Consider the following code.

import curses
import rlcompleter

def main(stdscr):
    while 1:
        c = stdscr.get_wch()

curses.wrapper(main)

When I run this and resize my terminal, the program fails at the get_wch, saying

Traceback (most recent call last):
  File "foo.py", line 8, in <module>
    curses.wrapper(main)
  File "/usr/lib/python3.3/curses/__init__.py", line 94, in wrapper
    return func(stdscr, *args, **kwds)
  File "foo.py", line 6, in main
    c = stdscr.get_wch()
_curses.error: no input

However, when I remove the line import rlcompleter, a KEY_RESIZE is correctly returned and everything works fine.

What is going on??

Était-ce utile?

La solution

I just tried this out, and you're a victim of http://bugs.python.org/issue2675 which is more a readline + curses problem than a Python issue.

In short, curses behavior changes based on the environmental variables LINES and COLUMNS, which readline sets.

If you add

import os

os.unsetenv('LINES')
os.unsetenv('COLUMNS')

Somewhere in there, it will remove the conflict and behave as you expect. If you want to be generous, you might want to save / restore =).

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top