Select to view content in your preferred language

import arcpy is crashing python

2480
14
01-02-2024 01:28 AM
CasperBørgesen
Regular Contributor

I am trying to debug a very simple python script:

import arcpy
print('OK')

I am using Visual Studio Code (Windows 10 x64) which has been executed from a BAT file which activates C:\Program Files\ArcGIS\Pro\bin\Python\Scripts\proenv.bat before hand to ensure that the python environment is setup for ArcGIS Pro usage.

When I try to debug the script sometimes the script prints OK and sometimes is just crashes python on the first line. A try/except doesn't work here since the first line is causing python to completely crash and it will never reach the except part. I can repeat running the script in debug mode and to me it seems very random if it completes or crashes.

So far I haven't found any log entries anywhere which describes what is happening. It could be that the import part is checking for a valid license (I am using concurrent licensing) and that something in that check is faulting but it is very difficult to tell since I get no clues at all from the crash.

Can anyone give me a hint to where I can find more details or what could be the reason for these crashes?

14 Replies
CasperBørgesen
Regular Contributor

Hi @HannesZiegler,

Thanks for responding! I have tried your settings for VS Code and I haven't been able to reproduce the issue when using just the following setting (made at least 20 runs and normally the issue appears after just a few):

"terminal.integrated.defaultProfile.windows": "Command Prompt",

Even when I still use my batch script to run VS Code, which looks like this:

@ECHO OFF

REM Set cmdcmdline to nothing to prevent proenv.bat from halting at the command line.
SET CMDCMDLINE=""

CALL "C:\Program Files\ArcGIS\Pro\bin\Python\Scripts\proenv.bat"

START "" "C:\Users\MYUSER\AppData\Local\Programs\Microsoft VS Code\Code.exe"

The reason for why I use a batch script is that I try to emulate our production where we call various arcpy scripts from outside ArcGIS Pro and the environment is setup the same way using proenv.bat. We can see that lots of the calls to the arcpy scripts just fails silently at the exact line where arcpy is imported. So my guess is that the issue with VS Code is related to what we see in production where VS Code is not used.

I haven't been able to find any crash dumps so far and I don't think its created.

I guess the default terminal in VS Code is powershell, so what is the difference between running import arcpy in powershell and command prompt? And why does the issue seem random when running in powershell?

0 Kudos
HannesZiegler
Esri Contributor

What release / patch of Pro are you using? I cannot repro the crash on my end. Are you able to reproduce it using the powershell alone?

0 Kudos
CasperBørgesen
Regular Contributor

I am using ArcGIS Pro 3.1.1. I have tried the following:

  1. Open a PowerShell terminal
  2. Run "C:\Program Files\ArcGIS\Pro\bin\Python\Scripts\proenv.bat"
  3. Run "python my_script.py"
  4. Repeat step 3 until it doesn't import arcpy

Following the above recipe my first step 3 failed, and after about 8-10 more times it failed again.

0 Kudos
HannesZiegler
Esri Contributor

Hi @CasperBørgesen, thank you for providing those additional details. I am still unable to reproduce the issue. If your organization has authorization, please reach out to Technical Support. Support will help you establish a reproducible workflow that will then help us debug and address the issue.

Note: To contact Technical Support, you need to be an authorized caller. See Why can't I submit cases? (Or, How I became an authorized caller and reported my issue) for more information.

0 Kudos
MichaelVolz
Esteemed Contributor

Has anyone tried to see if anti-virus and/or anti-malware software is the issue based on this documentation?

https://support.esri.com/en-us/knowledge-base/faq-how-do-i-troubleshoot-arcgis-pro-performance-issue...

Does anyone see any errors in Event Viewer?

Has anyone gotten a simple Pro based python script to work in previous versions (e.g. Pro 2.x)?  Just wondering if this functionality broke with Pro 3.x major release.

0 Kudos