I am working on a script tool to be run in ArcGIS Pro (version 2.4.0 with Python 3.6.8) and wish to give the user a warning message and also time to close a feature class so as to avoid the script breaking with a schema lock run time error. I tried applying the code from Pause ArcPy script until feature class lock goes away, however I find that the open feature class is caught when the code is run from an IDE (I'm using Spyder), but it is not caught when run from ArcGIS Pro's Interactive Python Interpreter window or when included in a script tool.
I've tried to make a minimum reproducible example (below). After making the test dataset, Example_Polygons, I open it in Pro and run the test schema lock code from both an IDE and the Pro Python window. lockTest is False in the IDE and True in Pro.
import arcpy, time # Create test polygon for minimal reproducible example arcpy.env.overwriteOutput = True if not arcpy.Exists(r"C:\Temp\test.gdb"): arcpy.management.CreateFileGDB(r"C:\Temp","test.gdb") arcpy.env.workspace = r"C:\Temp\Test.gdb" srWGS84 = arcpy.SpatialReference("WGS 1984") arcpy.management.CreateFishnet("Example_Polygons", "0 0", "0 1", 1, 1, 4, 6, None, "NO_LABELS", "DEFAULT", "POLYGON") arcpy.management.DefineProjection("Example_Polygons", srWGS84) # Code to compare between when run from IDE and from python interactive window (or potentially script tool) # Test schema lock lockTest = arcpy.TestSchemaLock('Example_Polygons') print(lockTest) # Give user message and time to close feature class while lockTest != True: time.sleep(10) lockTest = arcpy.TestSchemaLock('Example_Polygons') arcpy.AddMessage('Please close Example_Polygons') if lockTest == True: arcpy.AddField_management(in_table = 'Example_Polygons', field_name = 'wave_count', field_type = 'SHORT')
I came across https://support.esri.com/en/technical-article/000011739, which states that "The 64-bit background processing cannot gather the schema lock information across applications running as 32-bit." However, I don't think that is relevant in my case because I'm not running anything as 32-bit (to my knowledge).