This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: curses getkey() crash in raw mode
Type: Stage:
Components: Extension Modules Versions: Python 2.3
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: akuchling Nosy List: akuchling, bogjohnson
Priority: normal Keywords:

Created on 2004-02-09 07:11 by bogjohnson, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
curses-bug.py akuchling, 2006-11-07 14:36 Test script
Messages (5)
msg19946 - (view) Author: J. David Lee (bogjohnson) Date: 2004-02-09 07:11
Using python 2.3.3 on gentoo I have the following problem:

When calling stdscr.getkey() in raw mode, the program
crashes on a terminal resize event. In cooked and
cbreak modes, the proper string is returned -
"KEY_RESIZE". This problem appeared after upgrading
from python 2.3.2, I believe. Below is a quick program
that exhibits this behavior on my machine.

#######################################################
#!/usr/bin/env python

import curses;

stdscr = curses.initscr();
curses.raw();
curses.noecho();
stdscr.keypad(1);

while(1):
  stdscr.clear();
  stdscr.addstr("Enter key: ");
  c = stdscr.getkey();
  if(c == 'q'):
    break;
  stdscr.clear();
  stdscr.addstr('"' + c + '"\n\n');
  stdscr.addstr("Press any key...");
  stdscr.getkey();

curses.noraw();
curses.endwin();
#######################################################

A couple of other notes: 
1) No exception is thrown (a try block doesn't catch it).
2) The behavior is the same using the interactive
interpreter.
3) The traceback is: File "./keyname", line 19, in ?
stdscr.getkey(); _curses.error: no input
msg19947 - (view) Author: A.M. Kuchling (akuchling) * (Python committer) Date: 2004-04-19 12:45
Logged In: YES 
user_id=11375

1) and 3) are contradictory; 3 is certainly an exception
traceback.
When I try the test program on a Debian system, I get the
same error,
but a try:except: around the getkey() on line 19 lets the
program continue running.

Nothing in the Python curses module changed between 2.3.3
and 2.3.2.  Did gentoo switch to a new revision of the
ncurses library, perhaps?

msg19948 - (view) Author: J. David Lee (bogjohnson) Date: 2004-04-20 05:21
Logged In: YES 
user_id=971407

That Gentoo updated the ncurses library is quite possible.
Though the behavior is still incorrect as the documentation
says that getkey will return "KEY_RESIZE" on a terminal
resize event, and in fact it does in cooked and cbreak
modes, but throws an exception when in raw mode (though a
terminal resize isn't an exceptional circumstance).  Also, a
program can't assume that an exception on getkey() is a
resize event because an actual exception might occur and
need to be dealt with. 

For the present, though, the workaround is acceptable
because a real exception on getkey is very unlikely, as far
as I can see.
msg19949 - (view) Author: A.M. Kuchling (akuchling) * (Python committer) Date: 2006-11-07 14:32
Logged In: YES 
user_id=11375

After experimenting a bit with the attached test program, it
doesn't seem as if this is actually a bug in
the module; the ncurses docs themselves are vague on the
interaction between signals and a KEY_RESIZE.  So I'll close
this bug, because it doesn't look like there's anything in
Python to fix.
msg19950 - (view) Author: A.M. Kuchling (akuchling) * (Python committer) Date: 2006-11-07 14:36
Logged In: YES 
user_id=11375

Forgot to attach the script I was using.
History
Date User Action Args
2022-04-11 14:56:02adminsetgithub: 39918
2004-02-09 07:11:13bogjohnsoncreate