I have a python script, (for ArcGIS 10), that creates a new file geodatabase, creates a new feature class in that file geodatabase and then reads data from an SDE feature class to populate the new feature class. The script runs fine, except that a lock is placed on the file geodatabase that persists after the script is complete. The database cannot be deleted with ArcCatalog. Once the new feature class is deleted, then the file geodatabase can be deleted.

In the script I delete the references to all cursors and rows and yet still the lock remains. Below is the relevant code. What am I doing wrong?

import arcpy

OutputFolder = arcpy.GetParameterAsText(0)
FGDName = arcpy.GetParameterAsText(1)
StringInputWorkspace = arcpy.GetParameterAsText(2)

SourceFCAddressPoints = StringInputWorkspace + '\\sde.ERLANDSEN.AddressPoints'

## Create File GDB...
Output_gdb = OutputFolder + '\\' + FGDName + '.gdb'
arcpy.CreateFileGDB_management(OutputFolder, FGDName)

## Set current workspace to to file geodatabase
arcpy.env.workspace = Output_gdb
NewAddressPoints = Output_gdb + '\\AddressPoints'

## Create Feature Class...
arcpy.CreateFeatureclass_management(Output_gdb, "AddressPoints", "POINT", "", "DISABLED", "DISABLED", "PROJCS['NAD_1983_StatePlane_Washington_North_FIPS_4601_Feet',GEOGCS['GCS_North_American_1983',DATUM['D_North_American_1983',SPHEROID['GRS_1980',6378137.0,298.257222101]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Lambert_Conformal_Conic'],PARAMETER['False_Easting',1640416.666666667],PARAMETER['False_Northing',0.0],PARAMETER['Central_Meridian',-120.8333333333333],PARAMETER['Standard_Parallel_1',47.5],PARAMETER['Standard_Parallel_2',48.73333333333333],PARAMETER['Latitude_Of_Origin',47.0],UNIT['Foot_US',0.3048006096012192]];IsHighPrecision", "", "0", "0", "0")

## Add fields
arcpy.AddField_management(NewAddressPoints, "AddressPointID", "LONG", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")

curSourceAddresses = arcpy.SearchCursor(SourceFCAddressPoints)
curNewAddressPoints = arcpy.InsertCursor(NewAddressPoints)

for rowSourceAddress in curSourceAddresses:
    rowNewAddress = curNewAddressPoints.newRow()
    rowNewAddress.SHAPE = rowSourceAddress.SHAPE
    rowNewAddress.AddressPointID = rowSourceAddress.OBJECTID

del rowNewAddress
del rowSourceAddress
del curSourceAddresses
del curNewAddressPoints

3 Answers 3


Your not inserting the new row into your insert cursor, so ArcGIS is probably confused.

Try adding:


at the end of your for loop

  • 1
    Unfortunately that's just a result of a bad copy and paste on my part placing the code in the question. I am updating the cursor with the new row. Sorry about that, but good catch though.
    – Jeff Berry
    Feb 16, 2011 at 23:29
  • I've tried everything I can think of. I even tried deleting the reference to the new row at the end of the loop thinking it might be some sort of reference count issue. This is a script I am migrating for from 9.3 to 10, and I don't think I had this problem in 9.3.
    – Jeff Berry
    Feb 16, 2011 at 23:31
  • 3
    I think you have found a bug. I tried this ESRI example and it also leaves a lock after the script finishes that won't go away until the executing process exits (I tried both from ArcCatalog or PythonWin). I'd suggest you take this up with ESRI. Sorry. Feb 17, 2011 at 0:48

What I have found extremely handy to use in file geodatabase file locking instances is the Unlocker utility. In my several years of using it, it's never caused any data corruption.


Not familiar with ArcPy yet, but @ 9.3 deleting the geoprocessor object with del gp at the end of the script always works for me.

Maybe del ArcPy would work?

  • 2
    Deleting arcpy doesn't work because with arcpy you don't create an instance of a geoprocessing object as with previous versions. Rather, the arcpy namespace is imported. I think Regan is correct in that it's a bug.
    – Jeff Berry
    Feb 18, 2011 at 16:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.