Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
ghaefele opened this issue Oct 7, 2020 · 5 comments
Closed
Labels
bug Something isn't working

Comments

@ghaefele
Copy link

ghaefele commented Oct 7, 2020

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

@ghaefele
Copy link
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.

@fabioz
Copy link
Collaborator

fabioz commented Jan 15, 2021

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).

@ghaefele
Copy link
Author

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

@int19h
Copy link
Contributor

int19h commented Mar 31, 2021

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).

@int19h int19h added the bug Something isn't working label Mar 31, 2021
@int19h int19h closed this as completed Jun 9, 2022
@Ray-Mangan
Copy link

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

@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
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants