You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Debugger does not attach when running from ArcGIS Pro (Python Toolbox tool) #431
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.
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.
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()
…
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.
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).
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).
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.
Activity
ghaefele commentedon Dec 15, 2020
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 commentedon Jan 15, 2021
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 commentedon Jan 18, 2021
I meant if I disconnect then I can't attach again.
int19h commentedon 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).
Ray-Mangan commentedon Aug 1, 2022
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.