Nonblocking IO?

Nolan Darilek nolan_d at bigfoot.com
Wed Jul 5 12:53:02 EDT 2000


I'm trying to do nonblocking IO in a client application which I'm
writing. The client is text-based and line-oriented, and the cmd.Cmd
class does exactly what I want. (Well, almost exactly.) The class uses
raw_input(), which appears to block. I also moved the code which reads
from the connection into a thread, but this introduces a few more
problems; the output is intermingled with the input.

The most obvious solution is to use curses, but this makes my program
much more complex than it needs to be. Since cmd does almost exactly
what I want it to do, I'd much rather change the Cmd class than add
curses. I've seen code written in C which does what I'd like to do
(Micq, for example, has the interface which I'm aiming for, yet it
doesn't use curses/ncurses.) So, is it somehow possible to either a)
make raw_input nonblocking or b) use some other nonblocking IO method?
And, is it then possible to ensure that the output from the socket
isn't intermingled with the input? If I do nonblocking IO, I'm
assuming that it's simply a matter of printing a newline, my message,
and then reprinting the prompt while stuffing the existing input back
into the input buffer. (Of course, I'd rather delete the existing line
first to ensure that the app scrolls cleanly, but getting nonblocking
input to work would be a great step in that direction. :) Can anyone offer any suggestions?

Please CC me with any replies; I'm currently not subscribed to this
list, and I don't have usenet access for another week. Thanks.




More information about the Python-list mailing list