WindowsError: [Error 32]

by Lbook   Last Updated August 13, 2019 20:22 PM

I get a windows error when trying to run my tool again in the same arc project. It does run again once I shut down ArcMap and reopen and run the tool. Any Ideas?

  import arcpy, os, shutil, sys

# Path to store geoprocessing files
user_profile_path = os.environ['USERPROFILE']
gdb = r"{}/AppData/Local/Temp/PolyChecker/PolyCheck.gdb".format(user_profile_path)

# GDB already exists, delete it
if arcpy.Exists(gdb):

# Create fresh GDB path

# Create GDB
arcpy.CreateFileGDB_management(os.path.dirname(gdb), os.path.basename(gdb))

# Script arguments
MapUnitPolys = arcpy.GetParameterAsText(0)
if MapUnitPolys == '#' or not MapUnitPolys:
    MapUnitPolys = "MapUnitPolys"  # provide a default value if unspecified

MapUnitPolys_CopyFeatures = arcpy.GetParameterAsText(1)

# Set Geoprocessing environments
MapUnitPolys = MapUnitPolys

# Validate that all Polygons have a map unit

invalid_polygon_found = False

with arcpy.da.SearchCursor(MapUnitPolys, ['[email protected]', 'MapUnit', 'OBJECTID']) as cursor:
    for row in cursor:
        # Does this Polygon have a map unit
        if row[1] == "" or row[1] == "<Null>" or row[1] is None or row[1] is 0:
            invalid_polygon_found = True
            arcpy.AddMessage('Polygon OBJECT ID:{} is missing map unit... exiting.'.format(row[2]))

# Invalid polygons were found, terminate
if (invalid_polygon_found):

Polygon_Neighbors = "{}/polytest".format(gdb)

PolygonNeighbor_TableSelect = "{}/PolygonNeighbor_TableSelect".format(gdb)

inFeatures_lyr = "Polygon_Neighbors_tv".format(gdb)

# Process: Polygon Neighbors
arcpy.PolygonNeighbors_analysis(MapUnitPolys, Polygon_Neighbors, "OBJECTID;MapUnit", "NO_AREA_OVERLAP", "BOTH_SIDES",
                                "", "METERS", "SQUARE_METERS")

Polygon_Neighbors_tv = arcpy.MakeTableView_management (Polygon_Neighbors, "Polygon_Neighbors_tv") [0]
# Process: Select Layer By Attribute
arcpy.SelectLayerByAttribute_management(Polygon_Neighbors_tv, "NEW_SELECTION", "src_MapUnit = nbr_MapUnit")

# Process: Table Select
arcpy.TableSelect_analysis(Polygon_Neighbors, PolygonNeighbor_TableSelect, "src_MapUnit = nbr_MapUnit")



if int(arcpy.GetCount_management(PolygonNeighbor_TableSelect)[0]) > 0:
    arcpy.MakeFeatureLayer_management(MapUnitPolys, inFeatures_lyr)
    print ("done")

# Process: Add Join
arcpy.AddJoin_management(inFeatures_lyr, "OBJECTID", PolygonNeighbor_TableSelect, "src_OBJECTID", "KEEP_COMMON")

# Process: Copy Features
arcpy.CopyFeatures_management(inFeatures_lyr, MapUnitPolys_CopyFeatures, "", "0", "0", "0")

#arcpy.DeleteField_management("MapUnitPolys_CopyFeatures"["IdentityConfidence", "NODE_COUNT", "OBJECTID", "Label", "Notes", "Symbol"])

# Process: Remove Join
arcpy.RemoveJoin_management(inFeatures_lyr, "")

# Execute Delete

arcpy.AddMessage('All done! Check Polygons')


  Traceback (most recent call last):
      File "C:\Users\Downloads\GeMS-ArcPro-Toolbox-master\GeMS-ArcPro-Toolbox-master\Scripts\", line 9, in <module>
      File "C:\Python27\ArcGIS10.6\Lib\", line 261, in rmtree
        rmtree(fullname, ignore_errors, onerror)
      File "C:\Python27\ArcGIS10.6\Lib\", line 266, in rmtree
        onerror(os.remove, fullname, sys.exc_info())
      File "C:\Python27\ArcGIS10.6\Lib\", line 264, in rmtree
    WindowsError: [Error 32] The process cannot access the file because it is being used by another process: 'C:\\Users\\/AppData/Local/Temp/PolyChecker\\PolyCheck.gdb\\a00000009.gdbtable'

Related Questions

Updated November 01, 2017 10:22 AM

Updated June 20, 2018 18:22 PM

Updated August 13, 2019 16:22 PM

Updated September 05, 2017 16:22 PM