[Tutor] Non Blocking I/O on stdin

Girish Gajwani girishg@india.ti.com
Wed, 12 Sep 2001 01:14:37 +0530


Hi,

I wish to read the keyboard(stdin) but the read should not
be blocking

I essentially want to spawn off 2 threads, one of which will
constantly be reading from stdin. Just to give it a try, I
used the raw_input() & input() functions but neither of them
work. Infact they cause the program to quit. Is this due to
the non-blocking nature of the thread causing it to quit *
baffled *

                  ----------------------
                     consider this  
                  ----------------------


#### DOES NOT WORK ####

#! /usr/bin/env python
def acc(args):
    while(1):
        print "just b4"    # comes here
        str = input()
        print "just after" # never comes here :(

args = 0,                  # create list of arguments
thread.start_new_thread(acc, args)
#######################

                  ----------------------
                   & consider this now
                  ----------------------

#### THIS WORKS ####

#! /usr/bin/env python
def acc(args):
    while(1):
        print "just b4"    # comes here
        str = input()
        print "just after" # comes here but still not what i
want :(

args = 0,                  # create list of arguments
acc(args)
#######################
Also please advise on reading the keyboard in non-blocking
mode

Help wrt the thread module (scheduling, etc) will also be
helpful.

best regards
Girish