Skip to content

[MNT]: macosx event_loop_is_running is a deceptive name #32041

Open

Description

@iccir

Summary

The macosx backend has an event_loop_is_running method, documented as:

Return whether the macosx backend has set up the NSApp main event loop.

The method name is wrong, at least from the macOS perspective. The event loop is not running until a call to plt.show() or FigureCanvas.start_event_loop.

The documentation string is partially incorrect - the state of the event loop after we call lazy_init() is an implementation detail of NSApplication and PyOS_InputHook. It could still be "not set up" until the first call to CFRunLoopGet…().

Proposed fix

The method should probably be is_backend_initialized or something similar with a documentation string of:

Return whether the macosx backend has been initialized.

That said, event_loop_is_running needs to remain a method as it is being directly called by vispy's _detect_eventloop.py

Perhaps we should expose our _get_running_interactive_framework() as documented public API so other projects do not need to access backend internals?

Activity

  1. joddeepesh-cloud commented on Jul 18, 2026

    @joddeepesh-cloud
    Contributor

    Hi! I'd like to work on this issue. I'm currently investigating the implementation and the API usage to understand the proposed changes. If there are no objections, I'll prepare a PR based on the discussion here.

  2. iccir commented on Jul 18, 2026

    @iccir
    ContributorAuthor

    PRs are always welcome! That said, I think that this issue needs a discussion from project maintainers about what the exact policy should be when another project is using backend internals. I'm also not sure about the exact process of introducing new API. I suspect that this would involve a deprecation cycle at least for the event_loop_is_running name.

  3. joddeepesh-cloud commented on Jul 18, 2026

    @joddeepesh-cloud
    Contributor

    Thanks for the clarification! That makes sense. I'll hold off on proposing API changes until there's more guidance on the preferred direction and deprecation strategy. In the meantime, I'll continue exploring the codebase.

  4. timhoffm commented on Jul 22, 2026

    @timhoffm
    Member

    While it may be technically ok to expose _get_running_interactive_framework(), it's not really our responsibility to provide such a functionality. So I'm -0.5 on making this public. It's perfectly fine if vispy copies our implementation. Responsibility stays separated.

    On a broader note, IMHO vispy is working around an ipython deficit and what the'd really want is a function get_ipython().running_in_notebook().

    Since event_loop_is_running() is from the private _macosx module we formally could just rename, though we shouldn't consciously break vispy.

    What is feasible:

    1. define the new method
    2. make the event_loop_is_running() an alias to the new method
    3. pending deprecate it (formally we wouldn't need a deprecation, but it's a reminder to ourselves to remove it at some point in the future. And a direct deprecation would surface to vispy users which is also undesired.
    4. Before the PR gets merged, notify vispy about the upcoming change, ideally even advocate for a get_ipython().running_in_notebook(). method. At least, they have to switch and version gate on the new method, possibly on running_in_notebook().

    If somebody wants to take that effort, go for it. Otherwise, it would be a minimal good step to just document the imprecise naming in the docstring of event_loop_is_running().

  5. joddeepesh-cloud commented on Jul 25, 2026

    @joddeepesh-cloud
    Contributor

    I'd be happy to work on the suggested docstring clarification for event_loop_is_running() if no one else is already doing it .

  6. iccir commented on Sep 12, 2026

    @iccir
    ContributorAuthor

    I think get_ipython().running_in_notebook() is covered by How to detect which frontends are connected.

    tacaswell's 2019 comment:

    I think the protocol is carefully designed to make sure you can not tell. I have gone down this road with Matplotlib and concluded it was not possible (and mostly agree with the design).

    He later linked to our cbook code, which vispy then vendored. This body of this method will change in 3.12 to account for the new macOS backend. We will need to reach out to vispy regardless.

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