Skip to content

Enable gui event loop to run when a breakpoint is hit even if not using matplotlib #782

Closed

Description

@chubei-oppen

Currently debugpy checks if matplotlib is imported and runs its event loop if possible. This functionality can be useful for other libraries with their own event loop too.

For example, a 3D rendering library can register a inputhook and render one frame when called. This makes it possible to interactivly debug 3D rendering applications(games, scientific visualizations, etc.) with debugpy, specifically, in VS Code.

Very curious to hear your opinion about this.

Activity

  1. fabioz commented on Nov 15, 2021

    @fabioz
    Collaborator

    Well, actually, many input hooks are supported (see: https://github.com/microsoft/debugpy/blob/main/src/debugpy/_vendored/pydevd/pydev_ipython/inputhook.py#L25 for the ones supported).

    Some 3d libraries are actually supported already (glut/pyglet)... unfortunately, there's no standard API which would cover all existing libraries here, so, special code must be done in each case.

    Still, you're right in that those aren't run in general, only when using matplotlib as in matplotlib, keeping the loop running when a breakpoint is hit so that you can see the graphs does make sense, but I'm not sure if that'd be ideal for all other cases (i.e.: if you're in a game and hit a breakpoint, keeping the loop running may not really be what you want -- and if you want to render a single frame, you should be able to call the code to make a single iteration from the console evaluation).

    That being said, I guess there are cases where that will indeed make sense, so, maybe we could add some other setting to keep the loop running for some framework regardless of having matplotlib loaded.

    Note that this is a different task than having different custom hooks (that's already supported -- if you're missing a custom hook for a specific backend that we still don't support, please create a specific issue for that backend).

    I'll rename the issue accordingly (in that we should have an option to keep the loop running when a breakpoint is hit even if not using matplotlib).

  2. changed the title [-]Support custom gui event loop?[/-] [+]Enable gui event loop to run when a breakpoint is hit even if not using matplotlib[/+] on Nov 15, 2021
  3. chubei-oppen commented on Nov 15, 2021

    @chubei-oppen
    ContributorAuthor

    That option is absolutely great.

    Currently I have my custom 3d renderer(on top of winit) running in a manner similar to interactive matplotlib figures by first importing matplotlib and then calling set_inputhook. I have to manually trigger a breakpoint before setting hook because matplotlib hook is set by debugpy after hitting a breakpoint. If I set it early, my hook will be overwritten. The option can help here because I won’t need to import matplotlib or do the breakpoint hack anymore.

    In addition, I still feel a little uneasy because I’m calling a very nested function(set_inputhook), which seems like an implementation detail and can change in a future version of debugpy. Is it possible to make it a public interface?

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

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions