Repository: ipython/ipython

Issue:
show() blocks in pylab mode with ipython 0.10.1 
After updating to ipython 0.10.1 on 64-bit Linux, I noticed that plotting commands no longer automatically display anything when ipython is started with the -pylab option. Moreover, the show() command now appears to block in pylab mode. I don't have any local ~/.matplotlib/matplotlibrc file installed.



Discussion:
Ouch, it seems we have a nasty regression with GTK, which happens to be the default on linux.  Could you try starting it with 

ipython --pylab --qthread

or

ipython --pylab --q4thread

To use Wx or Qt instead?  Let us know how that goes, and if it works OK, it may be a necessary workaround until we find/fix the bug.

Wx and Qt/Qt4 work fine.

OK, thanks for the report.  We'll try to fix the gtk bug as soon as possible, though.  In the meantime, wx/qt will have to be the workaround.

Thanks, Fernando!

Took a quick look at this.
If I check out the 0.10.2 branch and invoke: ipython --pylab --gthread
it hangs.
Reverting commits 
3e84e9f (most recent commit to muck with GTK in Shell.py) and
dfb0d60d (which applies on top of the previous commit)
appears to fix the hanging problem.

My gtkfix branch (http://github.com/markvoorhies/ipython/tree/gtkfix) is 0.10.2 with
the above reversions, if anyone wants to try it.

Confirmed that "ipython --pylab --gthread" hangs prior to reverting 3e84e9f, but that
after reverting "ipython --pylab --gthread" works, "plot(rand(100))" works without
hanging, and "show()" also does not hang.

Keeping simple things simple - I can confirm that:
  $ ipython -pylab -gthread
  In [1]: ax = subplot(111); ax.plot(rand(10)); show()
all work, without blocking with just one line change to the current 0.10.2 branch, by uncommenting gtk.set_interactive(False) after gtk is imported on line 781 of Shell.py

http://github.com/ivanov/ipython/tree/fix185 

I updated to the 10.2 git branch just now, and while "ipython -pylab -gthread" leads to a working interpreter, "ipython -pylab" (no -gthread argument) exhibits the same problems described in the bug description.

Mmh, I see that.  It's very odd, but thanks for pointing it out.  I'll investigate further before pushing 0.10.2 out.

Any word on when 0.10.2 will be released?

Unfortunately I'm swamped and will remain so for the next 3-4 weeks.  The issue is that even in the 0.10.2 branch as it stands now, the regression isn't fixed.  Non-gtk backends work OK, but the gtk one remains borked, and if nobody submits a pull request with a good fix for it, I'll need some time to work on restoring the functionality myself.

So likely 3 weeks at best, I'm afraid.  Lack of manpower sucks...

The best way to help would be for someone to provide a pull request against 0.10.2 that fully fixes this, and then I could quickly cut a release.

I should have time to hack on this tomorrow night, but I'm having a bit of trouble
reproducing the bug.  If I check out 42cb9 (the 0.10.2 branch from 10/12) I can
reproduce the "ipython --pylab --gthread" freeze.  If I check out 8ed54 (Paul's fix),
81615 (Fernando's additional check_gtk calls), or 972dc (most recent 0.10.2 commit)
and test with:

ipython --pylab
ax = subplot(111); ax.plot(rand(10)); show()

I don't see blocking.  (This is on Ubuntu Lucid with up-to-date matplotlib)

Fernando or Drew, is there a better test case that I should be using?
(If not, I'll double check that I'm getting a clean rebuild of IPython after my checkouts)


Resolving patch:
diff --git a/IPython/Shell.py b/IPython/Shell.py
--- a/IPython/Shell.py
+++ b/IPython/Shell.py
@@ -1149,19 +1149,6 @@ def __init__(self,argv=None,user_ns=None,user_global_ns=None,debug=1):
 #-----------------------------------------------------------------------------
 # Factory functions to actually start the proper thread-aware shell
 
-def check_gtk(mode):
-    try:
-        import gtk
-    except (ImportError, RuntimeError):
-        # GTK not present, or can't be started (no X11, happens in console)
-        return mode
-    if hasattr(gtk,'set_interactive'):
-        gtk.set_interactive(False)
-        return 'tkthread'
-    else:
-        return mode
-
-
 def _select_shell(argv):
     """Select a shell from the given argv vector.
 
@@ -1231,10 +1218,6 @@ def _select_shell(argv):
             else:
                 # Any other backend, use plain Tk
                 th_mode = 'tkthread'
-
-            # New versions of pygtk don't need the brittle threaded support.
-            th_mode = check_gtk(th_mode)
-                
         return mpl_shell[th_mode]
     else:
         # No pylab requested, just plain threads
@@ -1242,10 +1225,6 @@ def _select_shell(argv):
             th_mode = special_opts.pop()
         except KeyError:
             th_mode = 'tkthread'
-
-        # New versions of pygtk don't need the brittle threaded support.
-        if th_mode == 'gthread':
-            th_mode = check_gtk(th_mode)
         return th_shell[th_mode]
 
 


Test patch: