# Cannot get rid of lock on file geodatabase and feature class created in Python script

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)

## 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

## Create Feature Class...



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

curNewAddressPoints.insertRow(rowNewAddress)


at the end of your for loop

• 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 '11 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 '11 at 23:31
• 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. – Regan Sarwas Feb 17 '11 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?

• 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 '11 at 16:17