Script crashing ArcMap - problems related to locks I think

Discussion created by paramatt on Jun 5, 2012
Latest reply on Jun 6, 2012 by paramatt
I have been having a heck of a time trying to get this script to run.  The best I get is it will run once, and crash the app the second time.  This makes me think it is a locking issue.  I haven't been able to get a clear reference on how this is handled in python / arcpy.  I am running 10.0 sp3, the referenced layers are in a file geodatabase for now.  I eventually wish to modify a SDE feature class, but I want to work out the bugs before I point this at my database. The commented out lines are my attempts to isolate problematic portions of script.  The long term goal of this script will be to copy the geometry from one feature class to another with a matching "MC911_ID" field, but I am stuck here thus far.  Any assistance is greatly appreciated.    

import arcpy

    drow, drows = None, None

    deltas  = arcpy.mapping.Layer("Deltas")
    base = arcpy.mapping.Layer("Baseline")
    dShape = arcpy.Describe(deltas).shapeFieldName
    bShape = arcpy.Describe(base).shapeFieldName
    drows = arcpy.SearchCursor("Deltas")
    dcount = 0
    bcount = 0
    for drow in drows:
        dID = drow.MC911_ID
        print("drow-" + str(dID))
        brow, brows = None, None
        brows = arcpy.UpdateCursor("Baseline",'"MC911_ID" = ' + str(dID))
        for brow in brows:
            bID = brow.MC911_ID
##            brow.MC911ID =  'Row Checked: ' + str(
            bcount = bcount +1
            if bID == dID:
##                brow.setValue("MC911ID", 'Matched') 
##                brows.updateRow(brow)          
                print("Match-" + str(bID))
##                brows.close()
        del brow
        del brows
        dcount = dcount +1
##    drows.close()
    print dcount
    print bcount
    print('Script Complete')      

except Exception as e:
    if not arcpy.GetMessages() == "":
        print("I am so sorry, there is a problem...")
        print e.message
        print dcount
        print bcount

    # Regardless of whether the script succeeds or not, delete 
    #  the row and cursor

    if drow:
        del drow
    if drows:
        del drows

    if deltas:
        del deltas
    if base:
        del base