Programmatically exit the REPL

David Huard david.huard at gmail.com
Tue Sep 16 16:25:13 EDT 2008


> [snip]
> 
> Does anyone know how to make raw_input think it has gotten input?
> 
> -Matt

Hi Matt, 

So you really need raw_input ? Couldn't you use a mock-up ?

sys.stdout.write('> ')
sys.stdout.flush()

And get the user input with something like: 

while self.continue:
  input = os.read(sys.stdin.fileno(), 80).strip()
  if input== '':
    time.sleep(.2)

The background thread can stop the listening thread by setting 
self.continue to False. 

The subversion trunk of pymc (on google code) has something that I think 
is similar to your problem, you might want to look at it (look at 
revision 868). 

HTH,

David Huard





More information about the Python-list mailing list