FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

When %matplotlib inline is ON gc.collect() runs on every cell execution · Issue #5795 · ipython/ipython · GitHub

Repository navigation

When %matplotlib inline is ON gc.collect() runs on every cell execution #5795

Closed

Description

Hi,

I'm not sure if it is the best place to put this issue. I'm working on an IPython notebook with a lot of objects loaded: len(gc.get_objects()) is about 5M. Everything works fine until an inline plot is drawn. Drawing itself is fast, but then there is a delay (5-10s). The delay is caused by gc.collect() executed by matplotlib: https://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/_pylab_helpers.py#L93. After the first plot the notebook becomes slow for all cells (even without inline plots). When interrupting the kernel (for cells without plots) I can see the same gc.collect() happening inside matplotlib.

As a workaround I'm monkey-patching gc.collect to be no-op, but this is clearly a hack.

It is gc.collect() call in matplotlib code that makes things slow, but why does IPython notebook need to call matplotlib code for cells without charts?

Activity

  1. minrk commented on May 6, 2014

    Member

    IPython makes matplotlib calls at the end of each cell to see if there are plots to draw. Can you tell what problematic call is being made (full stack up to an IPython call would be ideal) in a cell with no plots?

  2. kmike commented on May 6, 2014

    ContributorAuthor

    Here is a stacktrace for other cells (stacktrace for plots is the same):

    Traceback (most recent call last):
    
      File "/Users/kmike/envs/scraping/lib/python2.7/site-packages/IPython/kernel/zmq/ipkernel.py", line 389, in execute_request
        shell.run_cell(code, store_history=store_history, silent=silent)
    
      File "/Users/kmike/envs/scraping/lib/python2.7/site-packages/IPython/core/interactiveshell.py", line 2743, in run_cell
        self.events.trigger('post_execute')
    
      File "/Users/kmike/envs/scraping/lib/python2.7/site-packages/IPython/core/events.py", line 82, in trigger
        func(*args, **kwargs)
    
      File "/Users/kmike/envs/scraping/lib/python2.7/site-packages/IPython/kernel/zmq/pylab/backend_inline.py", line 118, in flush_figures
        return show(True)
    
      File "/Users/kmike/envs/scraping/lib/python2.7/site-packages/IPython/kernel/zmq/pylab/backend_inline.py", line 47, in show
        matplotlib.pyplot.close('all')
    
      File "/Users/kmike/envs/scraping/src/matplotlib/lib/matplotlib/pyplot.py", line 517, in close
        _pylab_helpers.Gcf.destroy_all()
    
      File "/Users/kmike/envs/scraping/src/matplotlib/lib/matplotlib/_pylab_helpers.py", line 93, in destroy_all
        gc.collect()
    
    KeyboardInterrupt
    
  3. minrk commented on May 6, 2014

    Member

    So it looks like the gc call wouldn't happen if we check whether there are any figures to close before calling close('all') (same goes for matplotlib's own destroy_all call).

  4. kmike commented on May 6, 2014

    ContributorAuthor

    Yes, it should fix it for non-plotting cells. I've fired a related issue to the matplotlib bug tracker.

  5. kmike commented on May 6, 2014

    ContributorAuthor

    btw, it's just amazing how fast are you responding to tickets here 👍

  6. added this to the 3.0 milestone on Oct 3, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL