for faq?: multithreaded curses getch()
Todd Owen
towen at nw.com.au
Sun Oct 3 03:55:41 EDT 1999
hi ho,
I just found a solution to a problem that bugged me for a while. I'm
sure a unix system programmer would have thought of this pretty soon,
but if someone maintaining the faq sees this, maybe they'll think it's
worth adding a sentence to question 4.74 (about getting keypresses),
since it sure would have helped me.
I'm writing a threaded python app which uses the curses module. I was
having trouble because in one place, one thread was waiting on a getch()
while another wanted to acquire the global interpretter lock. getch()
doesn't release the GIL (and it would be non-trivial to make it
thread-friendly methinks, since libcurses isn't to begin with??)
To get the getch thread to block without holding the GIL, the solution I
found was to do a select on stdin, as described in...
a faq-oriented summary :)...!
Hint for using curses module with threads: to wait for a keypress
without blocking other threads, try inserting a
"select.select([sys.stdin], [], [])" call before the call to getch().
maybe this will help someone.
Todd.
(PS I'm still looking for panelmodule!)
More information about the Python-list
mailing list