[IPython-dev] Re: [SciPy-dev] Generic gui_thread + IPython: solution already exists!

John Hunter jdhunter at ace.bsd.uchicago.edu
Mon Nov 15 11:04:56 EST 2004

>>>>> "Prabhu" == Prabhu Ramachandran <prabhu_r at users.sf.net> writes:

>>>>> "JH" == John Hunter <jdhunter at ace.bsd.uchicago.edu> writes:
>>>>> "Prabhu" == Prabhu Ramachandran <prabhu_r at users.sf.net> writes:
    Prabhu> Attached is a patch for IPython/Shell.py.  The diff is
    Prabhu> against the CVS version of Shell.py.  A summary of what
    Prabhu> I've done:

    JH> I haven't looked closely at this, but with ipython cvs + your
    JH> patch, I'm getting a lot of ipython shell freezes in pylab
    JH> mode with GTKAgg backend.

    Prabhu> More information would be appreciated as would test cases.
    Prabhu> My simple tests seem to work ok.  How about the other
    Prabhu> backends?  WXAgg, WX, GTK and GTKAgg all seem to work ok
    Prabhu> for me.  However, I have not really stressed anything out
    Prabhu> to really know for sure.

    Prabhu> BTW, I am using matplotlib version 0.62.4.

Oops, sorry, I'm lame.

This happens in --gthread and --wthread and so doesn't appear to be
matplotlib related; but for the record I'm using cvs matplotlib.

The freeze can be triggered simply by typing anything at the prompt

    > ipython --gthread
    >>> x = FREEZE

Ie, I just start typing some stuff, no additional imports, and the
shell freezes.  I can recover the shell by doing CTRL-C ENTER.

It doesn't always happen, but it happens a lot.  For example, in the
session below, I tried to type x = 123 but the shell froze

    peds-pc311:~> ipython --wthread
    Python 2.3.3 (#2, Apr 13 2004, 17:41:29)
    Type "copyright", "credits" or "license" for more information.

    IPython 0.6.4 -- An enhanced Interactive Python.
    ?       -> Introduction to IPython's features.
    %magic  -> Information about IPython's 'magic' % functions.
    help    -> Python's own help system.
    object? -> Details about 'object'. ?object also works, ?? prints more.

    1 >>> x = 12
    KeyboardInterrupt - Press <Enter> to continue.
    2 >>>

FYI, I had to hack hijack_wx because on my wx, there is no wx._core_.
It appears to be wx._core.  I don't know if a similar hack needs to be
applied to the 2.4 section.

 7 >>> wxPython.__version__
Out[7]: ''

Here's the modified hijack

def hijack_wx():
    """Modifies wxPython's MainLoop with a dummy so user code does not
    block IPython.  The hijacked mainloop function is returned.
    def dummy_mainloop(*args, **kw):
    import wxPython
    ver = wxPython.__version__
    orig_mainloop = None
    if ver[:3] == '2.5':
        import wx
        if hasattr(wx, '_core_'): core = getattr(wx, '_core_')
        elif hasattr(wx, '_core'): core = getattr(wx, '_core')
        else: raise AttributeError('Could not find wx core module')
        orig_mainloop = core.PyApp_MainLoop
        core.PyApp_MainLoop = dummy_mainloop
    elif ver[:3] == '2.4':
        orig_mainloop = wx._core_.PyApp_MainLoop
        wxPython.wxc.wxPyApp_MainLoop = dummy_mainloop
        warn("Unable to find either wxPython version 2.4 or 2.5.")
    return orig_mainloop

More information about the IPython-dev mailing list