Because I didn't find a better way to read keystrokes on command line I'm currently using getch()
.
Unfortunately using getch()
like this stops output on stdout
:
while True:
handle_keystroke(getch())
Pressing buttons triggers handle_keystroke()
and stdout
is being printed in the terminal - line by line for each keystroke.
Recommendations provided here didn't help.
What do I do wrong?
Btw: I do not need to use getch()
. Is there a better way (e.g. using select()
)?
Update: (changed the title)
All this becomes a problem only when you're using more than one thread. So it looks like getch
(which is a non Python function) doesn't release the GIL, so all other threads are suspended, so not only stdout
is affected.