[IPython-User] question about frontend-kernel interaction

Zoltán Vörös zvoros@gmail....
Mon Jul 9 16:44:28 CDT 2012

Hi Matthias,

On 07/09/2012 10:46 PM, Matthias BUSSONNIER wrote:
> Kernel.execute take a second argument that is a dict of callback (see IPython/frontend/html/notebook/static/js/codecell.js L161)
> If you don't specify how or by what the respond should be handled, the frontend will ignore the messages.
> Do you can either bound it directly to the current cell output handler, or, deal with it in a custom widget.
Something like the example 'directview'? I could try, though it seems a 
lot of trouble...:(
What is not clear to me at the moment is how I gain access to 'this' 
from within the notebook. What you suggest above is that I should have 
something like this for the kernel call

kernel.execute("pyfunc();", {'output': 
$.proxy(this.output_area.handle_output, this.output_area)});

but I don't know how to get 'this'.  I think, tying the output to the 
output handler would be fine with me.

By the way, the problem is not related to figures. This example does not 
display anything, while the code is actually executed. This I know from 
printing out the value of 'a'.

from IPython.core.display import display, HTML, clear_output

html = """<script type="text/javascript">
function jsfunction () {
     IPython.notebook.kernel.execute("a+=1; pyfunc();");
<input type="button" value="Click" onclick="jsfunction()" />
a = 1
def pyfunc():
     print 'hi!'

> and it seems to me that subsequent plots are never loaded to the 
> notebook.
> This is strange, I don't think it's an expected behavior. Do you have any output in the JS console ?
> The fact that kernel.execute didn't get any callback might screw up something somewhere.

I don't think anything is screwed up, something is just simply missing. 
And since there are no errors, the JS console is also empty.

More information about the IPython-User mailing list