Prevent Terminal Resize Python Curses
Solution 1:
Terminals are going to resize because users do that. There is no general way to prevent that: suppressing window decorations to eliminate the resize grips is a partial solution which is not portable. You may find occasional comments about different aspects of this, but no comprehensive solutions. Here are a few links:
- C ncurses prevent resize, which gives the same caveat
- How to prevent screen from resizing my Terminal in Mac OS X?, noting one special case where resizing can be disabled
- How to prevent Terminal from resizing when font size is changed, which disagrees with that, and mentions another special case.
In curses/ncurses (not in PDCurses), the library pays attention to the environment variables LINES
and COLUMNS
unless disabled with the use_env
function. ncurses adds a signal handler for SIGWINCH
during initialization which it uses to detect (and respond to) window-resizing (see resizeterm, for example). If these environment variables set, ncurses will not respond. However (see below) changing this special case will not make Python stop crashing, because Python has more problems than that.
ncurses has handled resizing of windows for almost 20 years; there are applications which fail to work with this. Without some specific test program to discuss, there is no way to determine the cause of a program's crashing.
Regarding the test program added early June 2:
Running your test-program with valgrind, I see a number of errors which are almost all in Python itself (2.6.6 and 2.7.9 on Debian 6 and 8), and a small fraction where Python is freeing memory owned by ncurses. In each case, Python is freeing memory which was already freed. It does this even without resizing (though some of the incorrect frees are related to resizing). I ran this several times, and at least once none of the errors detected were in ncurses. According to valgrind, there are a few dozen points in Python which produce these errors, a few of those account for 2/3 of the more than 400 occurrences it detected. So the question is misphrased. (I could suggest some improvements to the test program itself, but it seems the real problem is Python).
Post a Comment for "Prevent Terminal Resize Python Curses"