Yet another Schema Lock post...error with shapefile only

1718
13
11-03-2011 11:54 AM
LornaMurison
Occasional Contributor
Hi everyone,
I have a script which creates several intermediate files saved into a temporary location.  The user is allowed to select this location.
My code loops through features 300 at a time, performs some geoprocessing operations, and attempts to add a field and populate it with the area geometry.  This always works the first time through.  Once I get to the second loop though, if the intermediate files are being saved into a folder as shapefiles (rather than a geodatabase as feature classes), I get a schema lock error when trying to add the field.  I have overwrite output set to True, and there are several other files in the same folder which are successfully overwritten before encountering this error.  The actual shapefile whose attribute table I am attempting to edit has, in fact, just been successfully overwritten before encountering this error.
I know very little about schema locks, please help 🙂
Tags (2)
0 Kudos
13 Replies
JamesHood
Occasional Contributor

Could you please let me know if I have implemented your suggestions correctly, and if I have, do you have any others?? 😛
Thank-you!



I am theorizing that the search cursor is holding onto the editing rights of a shape file.

After the end of your search cursor loop add the following:

del row
del rows


Maybe that should free it up and hopefully drop the schema lock.
0 Kudos
LornaMurison
Occasional Contributor
I have found that I don't need to be able to get a schema lock on the feature layer I created (CatchLayer) in order for the code to work.
I added the lines del row and del rows.
I am still getting a cannot get exclusive schema lock error, in the following section:

lockTest = gp.TestSchemaLock (selectionDissInt)
    if lockTest:    
        ## Dissolve intersected features based on ID and land cover type, allowing multipart
        gp.Dissolve_management (selectionDissInt, tableName, idField + "; SCO_Class", "", "MULTI_PART", "") # <---- Fail
        print "dissolved intersected features based on ID and land cover type, allowing multipart"
    else:
        print "unable to get schema lock on selectionDissInt"

which is weird because it is only supposed to run the code once it is established that a schema lock is available...
0 Kudos
LornaMurison
Occasional Contributor
I now seem to be getting a sort of intermittent error.  Sometimes the dissolve in the code snippet above will work, and sometimes it won't, sometimes it will fail on the 3rd loop.  If it does work, the next process, Add Field, will (sometimes) be unable to acquire a schema lock.
Just now, for example, during the first loop, everything worked, during the second loop the dissolve worked, and the add field and calculate field were unable to obtain a schema lock, and during the 3rd loop the dissolve failed (it still got through the if TestSchemaLock: part, but then failed with a schema lock error).

I have tried the following to try and fix the schema locking error, all to no avail:
- Restart computer, clean out temp folder
- Create new folder to store interim files
- Create new folder to set as scratch workspace
- Add del row and del rows line after search cursor
- Run every process as a separate function
- Create short interim file names (a,b,c,d etc...)
- Save all outputs to a location with a short path (F:\Lorna\Temp)
- I am not running ArcCatalog or ArcMap
- Copy the "locked" file using CopyFeatures_management before running dissolve

I have no more ideas to try.
0 Kudos
LornaMurison
Occasional Contributor
I managed to solve this.
It was the same problem as discussed in this thread
The table view was causing the issue.  It has to have a different name each time it is created.  My solution was not to use a time stamp as discussed in the above thread, but to use the i variable from my loop.
Here is the code excerpt where I create a name for the table view.

    if wsType == "FileSystem":
    finalShp = "Rip" + str(bufferDistance) + "_" + str(i) + ".shp"
    elif wsType == "LocalDatabase":
    finalShp = "Rip" + str(bufferDistance) + "_" + str(i)


...
 tags are not formatting my tabs properly.
0 Kudos