[IPython-user] threaded ipython shell

Robert Cimrman cimrman3@ntc.zcu...
Thu May 14 08:56:13 CDT 2009


Replying to myself, a solution found, but not very pretty... I would 
appreciate some comments on what I did below.

Robert Cimrman wrote:
> Hi Fernando,
> 
> thanks for responding!
> 
> Fernando Perez wrote:
>> Hi Robert,
>>
>> 2009/5/6 Robert Cimrman <cimrman3@ntc.zcu.cz>:
>> No worries, I've been terrible at keeping up with public email due to
>> a massive set of grant deadlines over the last few weeks, sorry about
>> that.
> 
> It's sort of encouraging to hear that it is the same everywhere :)
> 
>>> ----
> 
>> This is pretty easy to do:
>>
>> #!/usr/bin/env python
>> """Simple customized ipython that specifically loads WX thread support"""
>>
>> # Shell class options (the last one is plain, unthreaded ipython):
>> # IPShellGTK, IPShellWX, IPShellQt, IPShellQt4, IPShell
>>
>> from IPython.Shell import IPShellWX
>>
>> # Main
>> banner ="Welcome to the SFEPy IPython-based shell with Wx support!\n"
>>
>> ipwx = IPShellWX()
>> ipwx.mainloop(banner=banner)
>>
>>
>> ### EOF
>>
>> I hope this helps,
> 
> This works great thanks! (I can get several mayavi windows popping out 
> now, all interactive.) However I still got a problem, maybe related to 
> the ipython version I use (0.9.1).
> 
> I have already tried using the IPShellWX directly, before I posted the 
> question, as:
> 
> ###
> def init_IPython():
>      from IPython.Shell import IPShellWX
>      return IPython.Shell.make_IPython(argv, shell_class=IPShellWX)
> 
> ip = init_Python()
> ip.runcode(ip.compile("from sfepy.interactive import *"))
> ###
> 
> because I need to run the initialization code at startup - that code 
> does some imports and sets up the environment so that the user has not 
> to import anything by hand and just starts computing. It is the pattern 
> I took from isympy. Then:
> 
> Traceback (most recent call last):
> line 25, in init_IPython
>      return IPython.Shell.make_IPython(argv, shell_class=IPShellWX)
>    File "/usr/lib64/python2.5/site-packages/IPython/ipmaker.py", line 
> 103, in make_IPython
>      embedded=embedded,**kw)
> TypeError: __init__() got an unexpected keyword argument 'embedded'
> 
> Should the above work just like your script, or is it a wrong way of 
> using IPShellWX?
> 
> thanks and cheers!

I can get both - the ability of runcode() and non-blocking mayavi2 by 
the following hack:

ip = IPython.Shell.make_IPython(argv)
ip.runcode(ip.compile("from sfepy.interactive import *"))

from IPython.Shell import IPShellWX
ipwx = IPShellWX(user_ns=ip.user_ns, user_global_ns=ip.user_global_ns)
ipwx.mainloop(banner=message)
#        ip.interact(message) # old way... blocking mayavi2

Any comments, please?

Best regards,
r.


More information about the IPython-user mailing list