Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Matplotlib 2 is extremely slow after plt.show() #8129

Open
tomchor opened this issue Feb 22, 2017 · 11 comments
Open

Matplotlib 2 is extremely slow after plt.show() #8129

tomchor opened this issue Feb 22, 2017 · 11 comments

Comments

@tomchor
Copy link

tomchor commented Feb 22, 2017

I recently upgraded to matplotlib 2.0.0 and it has this weird behavior in the interactive window where after I do a plt.show and close the interactive window, it hangs and I can't type anything. I can only type if I press control+c, but even so it takes about 15 seconds before the KeyboardInterrupt sets in and then I can type.

The behavior can be reproduced simple with this code

from matplotlib import pyplot as plt
plt.plot(range(10))
plt.show()

Apparently this only happens with IPython, since I tried in a simple python session and there was no problem. But I think it's not IPython-related because this never happened with any of the previous Matplotlib versions, just version 2. So I thought I'd post this here instead on the IPython issues.

Matplotlib version 2.0.0
Python version 2.7.12
IPython version 2.4.1
Linux Mint 18.1
get_backend() output: 'TkAgg'

@efiring
Copy link
Member

efiring commented Feb 22, 2017

What operating system, and what matplotlib backend?

That's a very old IPython version; can you try with a recent version?

@WeatherGod
Copy link
Member

WeatherGod commented Feb 22, 2017

@tomchor
Copy link
Author

tomchor commented Feb 22, 2017

Sorry, I forgot that information. Just updated the issue.

EDIT:

Just installed IPython 5.2.2 and the issue completely went away. I never noticed my IPython version was slow, so I never bothered to update it.

Apparently matplotlib doesn't work well with old versions of IPython. Although I never read that anywhere. Maybe there should be some note about that somewhere.

Thanks

@tacaswell
Copy link
Member

tacaswell commented Feb 23, 2017

It smells like Tk is not giving up control of the process?

I can confirm that closing the window does not exit (conda has old enough versions of everything!). This is specific to Tk (qt4 works as expected).

12:18 $ ipython                                                                                                                                                                                                    
WARNING: Readline services not available or not loaded.                                                                                                                                                            
WARNING: The auto-indent feature requires the readline library                                                                                                                                                     
Python 2.7.13 |Continuum Analytics, Inc.| (default, Dec 20 2016, 23:09:15)                                                                                                                                         
Type "copyright", "credits" or "license" for more information.                                                                                                                                                     
                                                                                                                                                                                                                   
IPython 2.4.1 -- An enhanced Interactive Python.                                                                                                                                                                   
Anaconda is brought to you by Continuum Analytics.                                                                                                                                                                 
Please check out: http://continuum.io/thanks and https://binstar.org                                                                                                                                               
?         -> Introduction and overview of IPython's features.                                                                                                                                                      
%quickref -> Quick reference.                                                                                                                                                                                      
help      -> Python's own help system.                                                                                                                                                                             
object?   -> Details about 'object', use 'object??' for extra details.                                                                                                                                             
                                                                                                                                                                                                                   
In [1]: import matplotlib                                                                                                                                                                                          
                                                                                                                                                                                                                   
In [2]: matplotlib.use('tkagg')                                                                                                                                                                                    
                                                                                                                                                                                                                   
In [3]: import matplotlib.pyplot as plt                                                                                                                                                                            
                                                                                                                                                                                                                   
In [4]: plt.plot(range(5))                                                                                                                                                                                         
Out[4]: [<matplotlib.lines.Line2D at 0x7fd48611b290>]                                                                                                                                                              
                                                                                                                                                                                                                   
In [5]: plt.show()                                                                                                                                                                                                 
^C---------------------------------------------------------------------------                                                                                                                                      
KeyboardInterrupt                         Traceback (most recent call last)                                                                                                                                        
<ipython-input-5-c4e69632d98a> in <module>()                                                                                                                                                                       
----> 1 plt.show()                                                                                                                                                                                                 
                                                                                                                                                                                                                   
/tmp/old_stuff/lib/python2.7/site-packages/matplotlib/pyplot.pyc in show(*args, **kw)                                                                                                                              
    251     """                                                                                                                                                                                                    
    252     global _show                                                                                                                                                                                           
--> 253     return _show(*args, **kw)                                                                                                                                                                              
    254                                                                                                                                                                                                            
    255                                                                                                                                                                                                            
                                                                                                                                                                                                                   
/tmp/old_stuff/lib/python2.7/site-packages/matplotlib/backend_bases.pyc in __call__(self, block)                                                                                                                   
    191                                                                                                                                                                                                            
    192         if not is_interactive() or get_backend() == 'WebAgg':                                                                                                                                              
--> 193             self.mainloop()                                                                                                                                                                                
    194                                                                                                                                                                                                            
    195     def mainloop(self):                                                                                                                                                                                    
                                                                                                                                                                                                                   
/tmp/old_stuff/lib/python2.7/site-packages/matplotlib/backends/backend_tkagg.pyc in mainloop(self)                                                                                                                 
     69 class Show(ShowBase):                                                                                                                                                                                      
     70     def mainloop(self):                                                                                                                                                                                    
---> 71         Tk.mainloop()                                                                                                                                                                                      
     72                                                                                                                                                                                                            
     73 show = Show()                                                                                                                                                                                              
                                                                                                                                                                                                                   
/tmp/old_stuff/lib/python2.7/lib-tk/Tkinter.pyc in mainloop(n)                                                                                                                                                     
    417 def mainloop(n=0):                                                                                                                                                                                         
    418     """Run the main loop of Tcl."""                                                                                                                                                                        
--> 419     _default_root.tk.mainloop(n)                                                                                                                                                                           
    420                                                                                                                                                                                                            
    421 getint = int                                                                                                                                                                                               
                                                                                                                                                                                                                   
KeyboardInterrupt:                                                                                                                                                                                                 
                                                                                                                                                                                                                   
In [6]:                                                                                                                                                                                                            
                

@malfatti
Copy link

malfatti commented Apr 20, 2017

I'm having this issue too with Tkagg. After plt.show(), figure shows, but then closing the window hangs the console forever. But I also had this issue with matplotlib 1.5.3.

OS: Gentoo Linux amd64
Python: 3.{5,6}
IPython: 5.3.0

@tacaswell
Copy link
Member

tacaswell commented Apr 20, 2017

att @Carreau I suspect that there may be some input hook issues with tk....

@tacaswell tacaswell added this to the 2.1 (next point release) milestone Apr 20, 2017
@malfatti
Copy link

malfatti commented Apr 20, 2017

I don't know if it helps, but this issue is not on matplotlib 1.5.1.

@tacaswell
Copy link
Member

tacaswell commented Apr 20, 2017

That makes it more likely to be a bug in the IPython tk inputhook. One of the changes is 1.5.3 is to automatically enable that if Matplotlib detects it has been imported inside of a IPython sessions (but 1.5.1 did not).

@Carreau
Copy link
Contributor

Carreau commented Apr 20, 2017

One of the possibility is to test with IPython 6 (released yesterday, Python 3 only) anduse https://github.com/ipython/rlipython as it we re-us readline and should skip the PTK eventloop. It should be backported to 5.4 but this has not been released yet.

I'm unfamiliar with Tk hooks, I'll see if I find time and manage to reproduce

@tacaswell tacaswell modified the milestones: 2.1 (next point release), 2.1.1 (next bug fix release) Sep 24, 2017
@tacaswell tacaswell modified the milestones: 2.1.1 (next bug fix release), 2.2 (next feature release) Oct 9, 2017
@malfatti
Copy link

malfatti commented Dec 5, 2017

Hello!

I still have this issue in 2.1.0-r1. I tried with IPython 6 and rlipython as suggested, but still the terminal hangs after closing the figure. Is there any possible workaround (so I don't stay trapped in 1.5.1 :) )?

Thanks :D

@tacaswell
Copy link
Member

tacaswell commented Dec 5, 2017

The issues #9077 #9856 #8845 may be related

The PRs
#9275 #9356 might help.

There is something funny going on with tk tear-down and probably requires someone who understands Tk to spend some time tracing exactly what is going on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants