Help setting up remote debugging

Mar 30, 2012 at 8:02 PM

First, I apologize - I'm very new to using Visual Studio in general.  I have been writing Python scripts using Eclipse/pydev but I wish to move to Visual Studio.  I have VS 2010 and have installed PyTools.  It appears to be working now that I got an interpreter working.

 

I am writing Python scripts for ArcGIS.  What I need to be able to do is debug the Python scripts as they run within ArcCatalog or ArcMap.  

I tried starting ArcCatalog and choosing Debug-> Attach, then choosing ArcCatalog.  VS goes into debug mode at this point and I have breakpoints defined.  When I run the script from ArcCatalog, despite the presence of breakpoints in VS, the script executes to completion without ever hitting my breakpoints.

How do I configure VS and PyTools to allow debugging scripts like this? 

 

Thanks for your help in advance!

Coordinator
Mar 30, 2012 at 8:37 PM

Are you certain the script is running in that specific process?  Could you do something like:

import os

print os.getpid()

To make sure the process is right?

The other possibility that springs to mind is if we're having trouble resolving the filename on disk to the code object loaded in the process.  You might be able to do something like:

while True:

    pass

 

And then hit the pause button in VS to break in.  Because the process will be constantly executing Python code we should have no problems breaking in.  Then in the call stack window you should see a stack trace.  It'd be good to know whether or not you can double click on the frames and have the files open.  If they don't open for some reason then there's a mismatch that we can dig into more.

 

 

May 1 at 12:54 AM
I am also trying to debug a Python script in PTVS starting from ArcMap or ArcCatalog. I have VS 2013 Express for Desktop installed along with PTVS 2.1 beta. VS functions as expected without ArcMap debug. When I execute "Debug" from ArcMap, Visual Studio opens with my Python script, but debug is grayed out. I can attach to ArcMap, then I see the lower status bar becomes orange. However, I cannot step into the script to debug. I've changed various VS settings but I cannot debug. Any ideas to get this working? I've successfully debugged python scripts starting ArcMap Debug with PyCharm, Pythonwin and PyScripter.
Coordinator
May 1 at 1:51 AM
I'm not sure what exactly executing "Debug" from ArcMap does, but from the docs it sounds like it simply loads the script for editing in the IDE that you set up in ArcMap? This would be consistent with the behavior that you're seeing, which is a single script opened in VS outside of any project. If so, then the reason why Debug is grayed out in VS is because it is a project command - standalone scripts can also be debugged, but you need to use the Start with Debugging command that will be under the Project menu, or in the context menu for the editor tab of the script. This, however, will simply run the script using your default Python interpreter (as configured in VS). Is it different with PyCharm and PythonWin?

Regarding attaching, can you make sure that in the Attach to Process dialog, the code type is "Python" for the ArcMap process (i.e. you're not attaching with the C++ or the .NET debugger)? Also, can you try doing what Dino suggested in the comment above - using the Pause command to break execution (instead of a breakpoint), and seeing where you end up in Call Stack window?
May 1 at 3:47 PM
@pminaev,

Thank you for your reply. The Project, Start with Debugging, is what I was missing. Now I'm able to set break points, debug and my messages are sent back to ArcMap. Thanks again.