Nonblocking IO?

Cliff Crawford cjc26 at nospam.cornell.edu
Mon Jul 10 20:50:30 EDT 2000


* Nolan Darilek <nolan_d at bigfoot.com> menulis:
| 
| 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?

You could use the select module to wait for input from multiple file
descriptors (for example, sys.stdin and a socket).  Also, the asyncore
module is a higher-level interface to select, and may be useful to you
too.


| 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.

Have you checked out the termios module?  That would be pretty much the
only other way to do it, besides curses (which is aptly named, don't you
think? ;)

curses-shmurses-ly y'rs, Cliff


-- 
cliff crawford    -><-    http://www.people.cornell.edu/pages/cjc26/
                          Synaesthesia now!            icq 68165166



More information about the Python-list mailing list