Raw_input with readline in a daemon thread makes terminal text disappear
John O'Hagan
research at johnohagan.com
Thu Oct 15 20:57:45 EDT 2009
I'm getting input for a program while it's running by using raw_input in a
loop in separate thread. This works except for the inconvenience of not having
a command history or the use of backspace etc.
That can be solved by loading the readline module; however, it results in a
loss of visible access to the terminal when the program ends: nothing is
echoed to the screen and the history is invisible (although it is there -
hitting return executes whatever should be there normally). The only way to
get it back is to close the terminal and open a new one.
Here is minimal code that reproduces the problem (python 2.5 on Linux):
from threading import Thread
import readline
get_input = Thread(target=raw_input)
get_input.setDaemon(True)
get_input.start()
If the thread is not set to daemon mode, there is no such problem (don't know
why this makes a difference), but in the real program, it needs to be a daemon
or it hangs the exit waiting for more input.
Any suggestions appreciated.
Thanks,
John
More information about the Python-list
mailing list