Make Layer Spatial Join Exclusive Lock Error

Discussion created by mykonosman on Mar 31, 2012
Latest reply on Apr 4, 2012 by kimo
Can anyone help me remove the lock on Parcels.shp in this script.  I get the exclusive lock error on the
gp.Delete_management(fc + "\\Parcels.shp")
part of the script because Parcels.shp is most likely being used in the feature layer above it. I tried deleting the layer, but that does not work.

import arcgisscripting
import logging
import os
import sys, string

logger = logging.getLogger()

# Create the geoprocessor object
gp = arcgisscripting.create(9.3)
gp.AddToolbox("C:/Program Files (x86)/ArcGIS/ArcToolbox/Toolboxes/Data Management Tools.tbx")
gp.OverWriteOutput = 1

# Set the workspace. List all of the folders within
gp.Workspace = "C:\\ZP44"
fcs = gp.ListWorkspaces("*","Folder")

for fc in fcs:
    gp.MakeFeatureLayer(fc + "\\Parcels.shp","lyr")
    gp.SelectLayerByAttribute_management("lyr", "NEW_SELECTION", "\"SIT_FULL_S\" >''")
    situscount = str(gp.GetCount_management("lyr").getoutput(0))
    if situscount == '0':
        print 'NO SITUS IN DATA'    
        gp.Delete(lyr, "layer") 
        print fc
        gp.AddSpatialIndex_management(fc + "\\Parcels.shp", "0", "0", "0")
        gp.SpatialJoin_analysis(fc + "\\Parcels.shp", 'C:\\ESRI\\ESRIDATA\\USA\\usa_zipcodes.shp', fc + "\\Parcelsjoined.shp", "")
        gp.CalculateField_management(fc + "\\Parcelsjoined.shp", "SIT_ZIP", "[POSTAL]", "VB", "")
        gp.CalculateField_management(fc + "\\Parcelsjoined.shp", "SIT_CITY", "[CITYNAME]", "VB", "")
        gp.DeleteField_management(fc + "\\Parcelsjoined.shp", "Join_Count;Join_Cou_1;Join_Cou_2;POSTAL")
        gp.Delete_management(fc + "\\Parcels.shp")
        gp.Rename_management(fc + "\\Parcelsjoined.shp", "Parcels.shp")

And here is the error:

Traceback (most recent call last):
  File "C:\Python24\ADDZIPNEW.PY", line 40, in <module>
    gp.Delete_management(fc + "\\Parcels.shp")
ExecuteError: ERROR 000464: Cannot get exclusive schema lock.  Either being edited or in use by another application.
Failed to execute (Delete).