Skip to content

[Bug]: Can not close figure when using multiple figures on MacOS X #28387

Closed

Description

@FengChendian

Bug summary

I can not close figure when use multiple figures.

I use

  • macOS 14.5 (23F79).
  • Apple M1 Pro

Code for reproduction

import matplotlib.pyplot as plt

import numpy as np

a = np.arange(10)
y = np.sin(a)

plt.figure()
plt.plot(a, y)
plt.figure()
plt.plot(a, y)
plt.show()

Actual outcome

Jietu20240613-121205-HD.mp4

Expected outcome

I should close these figures immediately.

Additional information

No response

Operating system

OS/X

Matplotlib Version

3.8.4

Matplotlib Backend

MacOSX

Python version

3.12.3

Jupyter version

No response

Installation

conda

Activity

  1. greglucas commented on Jun 13, 2024

    @greglucas
    Contributor

    I can reproduce this, but only when using tabbed window mode: plt.rcParams["macosx.window_mode"] = "tab".

    It looks like it was introduced by #27290 and reverting that commit does fix this issue on main for me. v3.8.1 works as expected, v3.8.2 is where this issue started to occur.
    cc @ksunden

  2. tacaswell commented on Jun 13, 2024

    @tacaswell
    Member

    Does reverting #27290 also bring back the segfault on py312?

    My guess is that we have generated some sort of deadlock on the GIL and probably need to change some of our logic on close on macOS to be "please exit when you can" from "please exit now, I'all wait"

  3. greglucas commented on Jun 13, 2024

    @greglucas
    Contributor

    Does reverting #27290 also bring back the segfault on py312?

    Yes, it sure does, sorry I shouldn't have implied we should revert it, just that reverting does get us the old desired behavior with tabs.

    My guess is that we have generated some sort of deadlock on the GIL and probably need to change some of our logic on close on macOS to be "please exit when you can" from "please exit now, I'all wait"

    I agree with this assumption of needing to update our logic.

  4. ksunden commented on Jun 14, 2024

    @ksunden
    Member

    Hmmm... interestingly, you can actually pull the tabs apart into separate windows, and then they close perfectly fine...

    I wonder if the deadlock is caused by dispatching the close signal to two tabs at once...

    I will note that it also freezes on hitting an individual tab close button, not just the red window close button.

    A few quick print debugging steps do in fact confirm that we are hanging at PyGILState_Ensure in _buffer_release. Though wonder if tracing back farther will be productive.

    Further, during normal separated window closing, _buffer_release is not called at all, so not sure why it is called when tabbed, perhaps it is closing one, triggering a draw on the other, even if they are closing?

  5. added a commit that references this issue on Jun 14, 2024
    6220fec
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions