[IPython-dev] Interactive wx/pylab with no threads (PyOS_InputHook)

Barry Wark barrywark at gmail.com
Sun Feb 8 23:49:07 EST 2009


I appologize for getting to the discussion late... There have been
several very interesting threads in the last couple of days. I'm
replying to this one arbitrarily, am intending to write more detailed
responses to some of the other threads, but wanted to throw this
general idea out there...

>From my reading, it seems that Brian is well on his way to having a
threading-free core for Qt and GTK. With the awesome new (in a recent
version, I forget which) OS X backend for matplotlib and the existing
ability of  Twisted's _threadedselect reactor to work with OS X's
CFRunLoop via PyObjC (it uses a very similar mechanism to the
PyOS_InputHook, no?), I suspect that a similar approach will work with
OS X as well. I know this may sound heretical to some, but if
supporting Wx GUI loops natively requires compromising the hackability
and testability of the IPython core, do we *need* to support it?

Just a 1c thought.

-Barry



On Sun, Feb 8, 2009 at 4:08 PM, Brian Granger <ellisonbg.net at gmail.com> wrote:
> IPython and matplotlib devs,
>
> Over the weekend I have been playing around to see if it is possible
> to do interactive GUI work with wx from IPython *without using
> threads*.  The idea here is to use PyOS_InputHook.  Currently, recent
> versions of PyQt4 and PyGTK do this and if we can get wx working, we
> can probably get rid of IPython's subtle threaded shells that
> currently allow interactive GUIs to work.
>
> I am attaching a Cython module that mostly works.  Here is a simple
> example that works in IPython (without the -wthread option!)
>
> In [1]: import pyximport
>
> In [2]: pyximport.install()
>
> In [3]: import inputhook
>
> In [4]: inputhook.set_input_hook()
>
> In [5]: import wx
>
> In [6]: app = wx.PySimpleApp()
>
> In [7]: app.MainLoop()
>
> In [8]: f = wx.Frame(None,-1,"Look mom, no threads!")
>
> In [9]: f.Show()
> Out[9]: True
>
> The docstring of the module also has a matplotlib example.  This
> really does work and I am pretty sure it will also work in plain
> vanilla python as well.  There are a few issues to work out:
>
> * When frame are closed by clicking the red button or the "X", the
> Windows don't close.  In addition, in matplotlib, this causes further
> problems.
>
> * In the current matplotlib backend wx.Yield() is called in a way that
> is not safe as far as protecting against recursive calls to Yield.  I
> think it should be called in this way:
>
> app = wx.GetApp()
> if app is not None:
>  app.Yield(True)
>
> * I don't think that interupts work yet, but I haven't tested this
> thoroughly yet.
>
> I don't have any more time to work on this right now, but I at least
> wanted to share my findings with both IPython and matplotlib devs.  It
> would be great if someone familiar with wx could try to figure out the
> remaining issues.  If there are no takers here, I might eventually see
> if wxpython itself is interested in this code (that is probably where
> it really belongs anyway).
>
> Cheers,
>
> Brian
>
> _______________________________________________
> IPython-dev mailing list
> IPython-dev at scipy.org
> http://lists.ipython.scipy.org/mailman/listinfo/ipython-dev
>
>



More information about the IPython-dev mailing list