Skip to content

Debugger does not attach when running from ArcGIS Pro (Python Toolbox tool) #431

Closed

Description

Environment data

  • debugpy version: 1.0.0 (latest version)
  • OS and version: Windows 10 Enterprise (1803)
  • Python version (custom Esri Miniconda environment): 3.6.10
  • Using VS Code or Visual Studio: VS Code 1.49.3
  • ArcGIS Pro version: 2.6.2

Actual behavior

Starting a ArcGIS Pro Python Toolbox tool and then the debug task (attach) in VS Code brings up the debugger button toolbar, but nothing happens after that.

Expected behavior

Start debugging should attach and stop at first breakpoint.

Background

A Python Toolbox tool runs within ArcGIS Pro (embedded Python) and for debugging it is necessary to remote attach to this process.
The debug server seems to start successfully. According to the adapter log file there are additional ports/processes involved.

2020-10-07_13-09-55

But both sides stay in a waiting status until the debugging process and the Python Toolbox tool are stopped. The processes (LISTENING…) still exists after this. Debugpy does not remove these processes on exit.
After that it is not possible to start the tool or the debugging process again. The existing processes seems to block everything.
I have to remove the processes manually (taskkill /PID … /F).

Debugging with ptvsd worked more or less well until June 2020.

Configuration

launch.json

…
       {
            "name": "Attach: connect",
            "type": "python",
            "request": "attach",
            "connect": {
                "port": 5678,
                "host": "127.0.0.1",
            },
            "logToFile": true,
        },
…

Code (Python Toolbox tool)
The issues #387 and #262 solved the problem that the listen process created a new ArcGIS Pro process. The workaround with sys.executable therefore can now be omitted.

…
import debugpy  
debugpy.configure(python="D:\\app\\miniconda_envs\\arcgispro-py3-clone\\python.exe")
debugpy.listen(5678)
arcpy.AddMessage("Waiting for debugger to attach...")
debugpy.wait_for_client()  
debugpy.breakpoint()
…

Log files

It is noticeable in the adapter log file that the ArcGIS Pro process is listed and not the Python process that was started by ArcGIS Pro.
debugpy.adapter-15908.log
debugpy.server-10300.log

Activity

  1. ghaefele commented on Dec 15, 2020

    @ghaefele
    Author

    With debugpy version 1.2.1, debugging of Python toolboxes (ArcGIS Pro 2.6.3) now works fine, at least with the attach configuration.

    Another small problem remains:
    If the debugging is interrupted prematurely, the processes (Python, Console Host Window, CefSharp.BrowserSubrocess) remain and ArcGIS Pro must be restarted in order to debug again.

  2. fabioz commented on Jan 15, 2021

    @fabioz
    Collaborator

    If the debugging is interrupted prematurely, the processes (Python, Console Host Window, CefSharp.BrowserSubrocess) remain and ArcGIS Pro must be restarted in order to debug again.

    What do you mean by interrupted prematurely?

    Note: the expected process is that you call debugpy.listen(...) once and then you should be able to attach / disconnect many times (so, if it's something within those boundaries it's a bug, but if it's not it's really something unsupported).

  3. ghaefele commented on Jan 18, 2021

    @ghaefele
    Author

    I meant if I disconnect then I can't attach again.

  4. int19h commented on Mar 31, 2021

    @int19h
    Contributor

    What is the lifecycle of Python code in ArcGIS like? Is there some main thread that stays alive all the time?

    I suspect that what's happening here is that your code runs to completion, and then the host kills all remaining Python threads (including the one waiting on the socket).

  5. added
    bug
    on Mar 31, 2021
  6. Ray-Mangan commented on Aug 1, 2022

    @Ray-Mangan

    With debugpy version 1.2.1, debugging of Python toolboxes (ArcGIS Pro 2.6.3) now works fine, at least with the attach configuration.

    Georg Haefele (@ghaefele) - I realize this is pretty old but I'm curious how you configured VS code to debug arcgis python toolboxes, been trying for a bit with no luck.

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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions