curses input with threads

Andrew Kuchling akuchlin at mems-exchange.org
Thu Jun 22 12:12:33 EDT 2000


"C. Porter Bassett" <porter at et.byu.edu> writes:
> screen.  I want to add a pause function.  I tried creating a separate
> thread that runs stdscr.getch() to catch the keyboard entries.  But when I
> do that, the entire program seems to pause to wait on that
> getch() function.  

The problem is that the curses module doesn't contain Py_BEGIN_THREAD
/ Py_END_THREAD calls around the call to getch(), to release the
global interpreter lock and let other threads run.  This is a bug
that's worth fixing for 1.6.

Which curses calls should release the interpreter lock?  All of them?
The ones which can actually pause for a long time?  getch() and
refresh() are the two obvious ones.  Adding BEGIN_THREAD/END_THREAD
refs to the various macros would take care of lots of other functions,
but I'm doubtful that it's worth the effort.

I'll try to check in this fix tonight; in the meantime you can add the
BEGIN_THREAD / END_THREAD to cursesmodule.c yourself.

--amk



More information about the Python-list mailing list