Select to view content in your preferred language

Has anyone successfully attached the VSCode Debugger to a Python toolbox?

1145
2
08-26-2021 01:11 AM
dstrigl
Regular Contributor

Has anyone successfully attached the VSCode Debugger to a Python toolbox?

I have a little Python toolbox and want to "debug" it in the way as described here:

Debug Python code—ArcGIS Pro | Documentation

But indead of using Visual Studio I want to use Visual Studio Code.

I have created the following launch file (launch.json)

 

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Attach using Process Id",
            "type": "python",
            "request": "attach",
            "processId": "${command:pickProcess}"
        },
        {
            "name": "Python: Current File",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal"
        }
    ]
}

 

copied the source of the MyToolbox.pyt file to a new MyToolbox.py file and replaced the source in the MyToolbox.pyt file with:

 

from MyToolbox import *

 

After starting my ArcGIS Pro and loading my sample project I started the Visual Studio Code debugger and attached it to the ArcGISPro.exe instance.

Afterwards I run my toolbox script, which doing its job, but the Visual Studio debugger is never triggered although I added some breakpoints!

Anyone an idea what's wrong or missing?

Regards,

Daniel.

2 Replies
DrewDowling
Frequent Contributor

I've got the same question. Did you manage to get it working? So far I haven't been able to get this to work.

0 Kudos
BrianWoodman
Emerging Contributor

I'm using VSCode to attach to my ArcPro 2.9 toolbox's Tool the same as you are and I'm using it to debug my Tool Validation code as described on the page you linked. You're right in your observation: Breakpoints I set are not recognized/do not halt the code but any print(messages) I insert are printed to the DEBUG CONSOLE tab. At least I'm getting some feedback while testing the Tool parameters. I'll strip out the print statements when I'm done.

If anyone knows how to get VSCode to recognize the Breakpoints and actually halt the code execution, I would be eternally grateful.