Skip to content

raw.plot(block=True) freezes the jupyter kernel forever #6528

Closed

Description

@wmvanvliet

Describe the bug

When plotting continuous "raw" data and specify block=True, everything works well until you try to close the figure. Control is never handed back to the command line. This does not occur when using command line ipython, but does occur when using Spyder or a Jupyter notebook.

Steps and/or code to reproduce

In Spyder or a notebook:

import mne
data_path = mne.datasets.sample.data_path()
raw = mne.io.read_raw_fif(data_path +'/MEG/sample/sample_audvis_raw.fif')
raw.plot(block=True)

Close the plotting window. The Jupyer kernel now hangs.

Expected results

After closing the window, the Jupyter kernel should become responsive again.

Actual results

Jupyter kernel never becomes responsive.

Additional information

Platform:      Linux-4.4.0-148-generic-x86_64-with-debian-stretch-sid
Python:        3.6.8 |Anaconda, Inc.| (default, Dec 30 2018, 01:22:34)  [GCC 7.3.0]
Executable:    /work/modules/Ubuntu/14.04/amd64/common/anaconda3/latest/envs/neuroimaging/bin/python
CPU:           x86_64: 8 cores
Memory:        15.6 GB

mne:           0.18.1 (also tested this on current master)
numpy:         1.16.4 {blas=mkl_rt, lapack=mkl_rt}
scipy:         1.2.1
matplotlib:    3.1.0 {backend=Qt5Agg}

sklearn:       0.21.2
nibabel:       2.4.1
mayavi:        4.6.2 {qt_api=pyqt5, PyQt5=5.9.2}
cupy:          Not found
pandas:        0.24.2
dipy:          Not found

Activity

  1. agramfort commented on Jul 4, 2019

    @agramfort
    SponsorMember
  2. Kriattiffer commented on Jul 8, 2019

    @Kriattiffer

    You may need to switch backedns with
    %matplotlib qt
    or
    %matplotlib tk
    when you need interactive plot

  3. wmvanvliet commented on Jul 9, 2019

    @wmvanvliet
    ContributorAuthor

    Yup, this is a jupyter/matplotlib issue. This also fails with the same behaviour on my end:

    from matplotlib import pyplot as plt
    plt.plot([1, 2, 3, 4])
    plt.show(block=True)
  4. agramfort commented on Nov 19, 2019

    @agramfort
    SponsorMember

    @wmvanvliet @SophieHerbst just reported the same problem. Did you end up solving this pb?

  5. wmvanvliet commented on Nov 19, 2019

    @wmvanvliet
    ContributorAuthor

    Unfortunately, no.

  6. mvonflotow commented on Aug 3, 2021

    @mvonflotow

    I was able to fix this for myself by disabling "Active support" for Matplotlib (under tools -> preferences -> IPython console -> Graphics), then manually setting the Matplotlib backend via:

    import matplotlib
    matplotlib.use('Qt5Agg')

    or: %matplotlib qt5, but Spyder complained about this version.

    Let me know if this works for you @wmvanvliet

  7. CarinaFo commented on Aug 31, 2021

    @CarinaFo
    Contributor

    Did anyone solve this issue for jupyter notebook? I am using matplotlib.qt and I get the mentioned kernel freeze.

  8. aroyphillips commented on Oct 12, 2022

    @aroyphillips

    I would like to reopen this issue as well for jupyter notebook. Is there a solution?

  9. cbrnr commented on Oct 12, 2022

    @cbrnr
    Contributor

    I cannot reproduce the issue, the minimal example does not block execution in both a regular Jupyter notebook and inside VS Code. Maybe you do not have the latest versions of the involved packages (i.e. Matplotlib, Jupyter)?

  10. wmvanvliet commented on Oct 12, 2022

    @wmvanvliet
    ContributorAuthor

    This still breaks for me in Spyder, but not in plain ipython or in a notebook:

    from matplotlib import pyplot as plt
    plt.plot([1, 2, 3, 4])
    plt.show(block=True)

    However, @mvonflotow's suggestion of disabling Spyder's active support did the trick. I'm guessing there's some weird interaction between the Qt thread spawned by the QtConsole component that Spyder uses and the block=True behavior. I'll file the issue there.

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions