question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Some matplotlib backends on MacOS significantly slow down jupyter

See original GitHub issue

On my MacOS Mojave system, enabling some matplotlib backends will significantly slow down the execution of subsequent cells (the slowdown starts to occur about half a minute after setting the backend). See the screenshot below for an example (notice the 10.0s execution time of the third cell):

image

In particular, I notice that the 10.0s consists of three “stages”:

  1. After I tell jupyter to run the cell, the kernel stays idle for a few seconds;
  2. The kernel becomes busy, and the output immediately appear;
  3. The kernel stays busy for another few seconds after the output appears.

I’ve tested with different matplotlib backends, and the issue happens when using some of the backends. Here is a summary:

  • Backends that make this issue happen:
    • osx
    • qt
  • Backends that do NOT make this issue happen:
    • inline
    • agg
    • tk
    • nbagg
    • notebook

I’ve also tested with different ipython/jupyter clients, and the issue happens when using some of the clients. Here is a summary:

  • Clients where this issue happens:
    • jupyter notebook
    • jupyter console
    • jupyter qtconsole
    • jupyter lab
    • Nteract app
  • Clients where this issue does NOT happen:
    • ipython console

When tested in jupyter console, an additional warning is cast when executing the third line in the screenshot above:

/usr/local/lib/python3.7/site-packages/jupyter_console/ptshell.py:661: UserWarning: The kernel did not respond to an is_complete_request. Setting `use_kernel_is_complete` to False.
  warn('The kernel did not respond to an is_complete_request. '

I have tried to dig into the source code of IPython.core.pylabtools.activate_matplotlib, and here is a minimal (to my best) example:

$ jupyter console
Jupyter console 6.0.0

Python 3.7.2 (default, Jan 13 2019, 12:50:01)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.2.0 -- An enhanced Interactive Python. Type '?' for help.



In [1]: import matplotlib

In [2]: matplotlib.rcParams['backend'] = 'MacOSX'

In [3]: import matplotlib.pyplot

In [4]: import time

In [5]: time.sleep(35)

In [6]: 'test'    # this line will take a lot of time
/usr/local/lib/python3.7/site-packages/jupyter_console/ptshell.py:661: UserWarning: The kernel did not respond to an is_complete_request. Setting `use_kernel_is_complete` to False.
  warn('The kernel did not respond to an is_complete_request. '
Out[6]: 'test'

My system information that might be relevant:

$ python3 -c "import IPython; print(IPython.sys_info())"
{'commit_hash': '523ed2fe5',
 'commit_source': 'installation',
 'default_encoding': 'UTF-8',
 'ipython_path': '/usr/local/lib/python3.7/site-packages/IPython',
 'ipython_version': '7.2.0',
 'os_name': 'posix',
 'platform': 'Darwin-18.2.0-x86_64-i386-64bit',
 'sys_executable': '/usr/local/opt/python/bin/python3.7',
 'sys_platform': 'darwin',
 'sys_version': '3.7.2 (default, Jan 13 2019, 12:50:01) \n'
                '[Clang 10.0.0 (clang-1000.11.45.5)]'}

$ pip3 freeze | grep 'jupyter\|matplotlib'
jupyter==1.0.0
jupyter-client==5.2.4
jupyter-console==6.0.0
jupyter-contrib-core==0.3.3
jupyter-contrib-nbextensions==0.5.1
jupyter-core==4.4.0
jupyter-highlight-selected-word==0.2.0
jupyter-latex-envs==1.4.6
jupyter-nbextensions-configurator==0.4.1
matplotlib==3.0.2

Thanks!

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

0reactions
ccordoba12commented, Dec 11, 2020

Ok, closing then.

Read more comments on GitHub >

github_iconTop Results From Across the Web

IPython notebook interface much slower on Safari than ...
I am noticing that ipython notebook is slow when using in Safari than when using in Chrome (both on OS X Yosemite). Navigating...
Read more >
Using matplotlib in a python shell
By default, matplotlib defers drawing until the end of the script because drawing can be an expensive operation, and you may not want...
Read more >
Cripplingly slow UI: am I the only one? - JupyterLab
The lag is not very bad if I open a fresh instance with no open notebooks (although even then, the UI seems much...
Read more >
PyPlot · Julia Packages
This package takes advantage of Julia's multimedia I/O API to display plots in any Julia graphical backend, including as inline graphics in IJulia....
Read more >
Getting started — HyperSpy 1.4.2 documentation
The examples in some later sections assume Notebook operation. ... When using the qt4 backend in Python 2 the matplotlib magic must be...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found