Skip to content

Add ability to specify files to skip debugging #1170

Closed

Description

@AlexSWall

This is similar to justMyCode, but more fine-grained.

In my use of debugpy, another python file is being run to run my unittests, and therefore after debugging a unit test I always end up in this file. It would be great to be able to specify manually to never debug it.

Activity

  1. karthiknadig commented on Jan 11, 2023

    @karthiknadig
    Member

    We do have it, it is un-documented feature:

           {
                "name": "Python: Current File",
                "type": "python",
                "request": "launch",
                "program": "${file}",
                "console": "integratedTerminal",
                "justMyCode": true,
                "rules": [
                        {"path": "path_to_file_or_dir", "include": false},
                ]
            }
  2. AlexSWall commented on Jan 12, 2023

    @AlexSWall
    Author

    Ah great, thanks, I realize why it wasn't working for me initially. I was including ~ at the start for my home directory, and this didn't expand.

  3. ezhang7423 commented on Mar 27, 2024

    @ezhang7423

    Thanks, this worked perfectly for me!

  4. lionpeloux commented on Oct 11, 2024

    @lionpeloux

    Hi there,

    I have a project with a huge (350k lines) persisted search index that I've put in a global variable in my __init__.py :

    # in file : ___init__.py
    # type:ignore
    COMMUNES_INDEX = {
        "01001": {
            "nom": "L'Abergement-Clémenciat",
            "codeDepartement": "01",
            "siren": "210100012",
            "codeEpci": "200069193",
            "codeRegion": "84",
            "codesPostaux": ["01400"],
            "population": 832,
        },
        "01002": {
            "nom": "L'Abergement-de-Varey",
            "codeDepartement": "01",
            "siren": "210100020",
            "codeEpci": "240100883",
            "codeRegion": "84",
            "codesPostaux": ["01640"],
            "population": 267,
        }, ...

    This index is basically a dict with all the cities of France, with keys as city_code.

    When I try to debug my project it spends an infinite time to just import the variable COMMUNES_INDEX (honestly I've never had the patience to wait until this step is done, it is useless) :

    # in file : module.py
    from api.services import COMMUNES_INDEX

    Note that I encounter no problem to run my code (not in debug mode).

    So I want to tell debugpy to not debug the __init__.py file at all. Is there anyway I can achieve that ? The trick proposed here does not work on my setup. In the launch.json I have this warning : Property rules is not allowed.

    {
        "configurations": [
            {
                "name": "Python Debugger: Current File",
                "type": "debugpy",
                "request": "launch",
                "program": "${file}",
                "console": "integratedTerminal",
                "justMyCode": true,
                "rules": [
                    {
                        "path": "path_to_file_or_dir",
                        "include": false
                    },
                ]
            },
        ]
    }
  5. rchiodo commented on Oct 11, 2024

    @rchiodo
    Contributor

    The warning in the launch.json is because the "rules" option is undocumented. VS code doesn't know about it. It's implemented here:

    Did you try 3.12? Might be a lot faster. I think it depends upon whether or not we're trying to eval that giant dict.

  6. lionpeloux commented on Oct 18, 2024

    @lionpeloux

    Ok, I've just came back to this today, and now it is working, I really dont know why/how ...
    I'm on 3.12 indeed.
    Thanks for your quick reply anyway !

  7. darkguy2008 commented on Apr 29, 2025

    @darkguy2008

    I think this feature should be improved or at least make more user-friendly like in C# where when clicking "All Exceptions" in VSCode for C#, it allows you to write an expression to skip functions or similar.

    I am having an issue where in Python, that feature for "Raised Exceptions" does not exist, so I am having a hard time trying to skip files for debugging breakpoints, specifically: "/pymeta_generated_code/pymeta_grammar__Grammar.py" since there's no way to copy the file path with right-click, so I have to do it manually per each friggin' file that appears.

    Oh, I so wish there was a feature where you could right-click the open tab in VSCode and have an option that says "Skip file for breakpoints" and it auto-adds the file in your VSCode exception system, just like good ol' Visual Studio.

  8. rchiodo commented on Apr 29, 2025

    @rchiodo
    Contributor

    The rule does support globs, You should be able to add a glob like /pymeta_generated_code/**/*.py

  9. dobos commented on Jun 24, 2025

    @dobos

    Are rules supposed to work with unit tests? I'm having trouble with third-partly libraries that are installed to a non-standard location and added to PYTHONPATH one by one. The debugger thinks it's my code but I want to ignore exceptions that are raised from the third-party lib but handled by the standard library between my code and the third-party lib.

  10. rchiodo commented on Jun 24, 2025

    @rchiodo
    Contributor

    The rules should allow you to mark any file as 'system' code (or not included).

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