[IPython-dev] using ipkernel to provide access to an application's internals

Ivan Zhang mirage007 at gmail.com
Fri Feb 24 09:15:12 EST 2012


Hi dev list,
I thought this place more appropriate as I am looking to change the
internals of IPKernel, or perhaps just extend it. Perhaps I am simply not
experienced enough with the code and this is already done and obvious,
forgive me in this case.

Say I have a typical python gui that creates some python objects, modifies
them, etc...Now instead of just running this code directly, say I want to
run this inside the IPKernel so that all of its data can then be inspected
by someone connecting an qtconsole to it.

i.e.  I envision something like this rough pseudocode below:

>from ipython.zmq.ipkernel import *
>
>class someGui():
>
>                 controller = Controller()
>
>
>
>                 def onSomeEvent(self):
>
>                                 self.controller.doSomething()
>
>
>
> class Controller():
>
>
>
>                 def __init__(self):
>
> self.app = IPKernelApp.instance()
>
> self.app.initialize()
>
> self.app.start() //make this a returning call so that this doesn’t hang
forever.
>
>
>
> def doSomething(self):
>
>                 self.app. execRequest (“a = 5”)
>
>
>
> def doSomethingElse(self):
>
>                 return self.app.evalRequest (“a”)
>
>
>
> def main():
>
> gui = someGui()
>
> gui.show()
>
> ____________________
Now somewhere else, someone starts a qtconsole and type in ‘a’ to check
that it’s 5.

It’s fairly obvious that the implementation of qtconsole already does
something similar, but it was my understanding that it communicates to the
kernel through zmq (perhaps I am mistaken?) In my example, I kind of want
to give this gui special status, i.e. it is in the same process as the
ipkernel itself (maybe another thread) but it would talk to ipkernel
directly instead of via zmq.
So basically my 2 basic questions are:

1.       How to make the ipkernelapp.start() non blocking, or dispatch it
as another thread that I can call additional functions on.

2.       How to make a simplified exec/evalRequest a blocking call that
would evaluate the code on the spot and return or maybe after waiting to
acquiring some lock, i.e. not interweaved as an iteration of the ipkernel
event loop to make it as responsive as a regular application as possible.

3.       How to create the option to broadcast any errors(or print
statements) to connected qtconsole instances.

If anyone can provide some clues as how to get started towards this
direction, it would be greatly appreciated.

-i

-- 
Ivan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ipython-dev/attachments/20120224/6fdf3130/attachment.html>


More information about the IPython-dev mailing list