[IPython-user] Sending input to IPython from a separate thread.

Anthony Roy home@antroy.co...
Wed Sep 26 03:44:24 CDT 2007

Hi all,

I'm starting to write a Vim plugin for sending text for a buffer to 
IPython for evaluation. The idea is to send the text via sockets to a 
thread on a running instance of IPython which will then evaluate the text.

A simplified version of what I am trying to achieve follows:

import sys, threading
from IPython.Shell import *#IPShellEmbed

def get_shell_runner(shell):
     def shell_runner():
         shell(header='Vim Interactor')
         print dir(shell)
     return shell_runner

ipshell = IPShellEmbed()
t = threading.Thread(target=get_shell_runner(ipshell))

ipshell.IP.runsource("2 * 3")

Now this falls over due to the history object (IP.input_hist) isn't 
getting updated. So I'm fairly sure I'm using the wrong method to send 
the text to the shell.

What I want to see on the screen is the following:

In [1]: 2 * 3
Out [1]: 6

What I'm actually getting (after hacking the Prompts module to suppress 
the error...) is this:

1]: In [1]: 6

Any tips anyone?



e: home@antroy.co.uk

More information about the IPython-user mailing list