for faq?: multithreaded curses getch()

towen at nw.com.au towen at nw.com.au
Mon Oct 4 01:25:48 EDT 1999


On 3 Oct 1999 22:41:20 GMT, cjc26 at nospam.cornell.edu (Cliff Crawford)
wrote:

>Pada Sun, 03 Oct 1999 15:55:41 +0800, Todd Owen bilang:
>| 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().
>
>stdwin.nodelay(1) also works--it causes getch() to always be non-blocking.

Yes that would be good for some situations (especially
single-threaded).  In this case however I didn't mind blocking the
user-input thread while waiting for a character to arrive, but I
wanted other threads to be able to run while it was waiting for input.
On a C-implementation level, the select() call is wrapped in
"Py_BEGIN_ALLOW_THREADS/Py_END_ALLOW_THREADS", whereas the getch()
call isn't.

Todd.





More information about the Python-list mailing list