UrbisMelbourne

arcpy UpdateCursor "cannot acquire a lock"

Discussion created by UrbisMelbourne on May 20, 2012
Latest reply on Sep 28, 2016 by rastrauch
I'm pretty new to Python, and I'm trying to put together a script which will, after doing a bunch of other stuff, update a column conditionally based on the contents of another column.  The relevant code is:

rows = arcpy.UpdateCursor(r"C:\TEMP\storesgathered.shp")
for row in rows:
    if row.getValue("CenType") == "REG":
        arcpy.CalculateField_management(r"C:\TEMP\storesgathered.shp", "Adj_X", 8)
    else:
        arcpy.CalculateField_management(r"C:\TEMP\storesgathered.shp", "Adj_X", 9)
    rows.updateRow(row)
del row, rows


So basically it's supposed to look at each row in "CenType", check if it equals "REG", and calculate out "Adj_X" with the relevant value.  The calculate field values for "Adj_X" are just dummy values at this point, to see if I can get it working.  The final script will have a bunch of elifs as well, to account for all of the possible values in "CenType".

The problem is, when I run it, I get this:

Runtime error <class 'arcgisscripting.ExecuteError'>: ERROR 999999: Error executing function. Cannot acquire a lock. Cannot acquire a lock. [The table storesgathered.shp is being written by another process.] Failed to execute (CalculateField).


This is a really stubborn lock too - removing the layer from the TOC isn't enough; I need to exit all the way out of ArcMap to release it.  I've tried running the snippet of code externally from IDLE as well, but the shapefile still gets locked.  I've even tried exporting the shapefile to an in_memory entity, but it still gets locked.

I'm sort of out of ideas here.  Is there something obvious I'm doing wrong, or is there another approach that will get me the same results?

Outcomes