This simple app serves as a minimal example:
import curses
def main(stdscr):
while True:
stdscr.clear()
window_size = stdscr.getmaxyx()
stdscr.addstr(1, 1, str(window_size))
stdscr.refresh()
if stdscr.getch() == 17: # Ctrl + Q
break
if __name__ == "__main__":
curses.wrapper(main)
The app prints the current window size on the screen. I expect that if I resize the window while the program is running, the numbers will change. And it does exactly that.
The problem is I'm using curses
in a larger application that also needs the module readline
(following this answer). And I found out that if readline
is imported (doesn't even have to be used), the above program no longer works: the numbers still show up, but they do not get updated when the screen size changes.
It took me hours to track down this bug, as I would never have expected that merely importing a module -- without using it -- could change the program's behavior.
Theoretically, what is causing this behavior? And practically, how can I resolve this conflict? I have tried only importing readline
inside functions that need it, but that doesn't work either: once a function that imports readline
is called, the curses
app stops working.
As I'm writing this question, I find out someone already asked the same question. The question had no answers, so I hope it's fair to ask it again.