Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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
share|improve this question

2 Answers 2

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?

share|improve this answer
1  
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

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

Try adding:

curNewAddressPoints.insertRow(rowNewAddress)

at the end of your for loop

share|improve this answer
    
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
2  
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
    
I think you're right. Thanks for the help. –  Jeff Berry Feb 18 '11 at 16:06

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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