Tag Archives: gc

ESRI/arcpy – Locked Files

When working with geoprocessing tools in ArcGIS, especially using arcpy, you quickly learn about locked files. These files are locked because they are currently being edited, or being viewed in ArcCatalog, or otherwise accessed with ESRI products. This creates a LOCK files that is displayed in e.g. Windows Explorer. Typically, upon successful completion of your geoprocessing task, the lock is removed (the LOCk files disappears). Unfortunately, when you run arcpy scripts outside of ArcMap’s Python window, oftentimes this doesn’t work, especially with cursors. I have found that I was getting errors like:

ExecuteError: ERROR 000258: Output C:/temp/myfile.shp already exists
Failed to execute (CreateFeatureclass

That despite the fact that I had set

arcpy.env.overwriteOutput = True

(see me last post). So it’s a good habit to delete any references to cursors, e.g.:


del row #unlock row
del rows #unlock table
del arcpy

A couple of links with similar explanations are here: from ESRI (scroll down on page), and from Penn State GIS. Also very useful is Python garbage collection module to force deleting any references to strange objects or files you may be missing. Very simply:


import gc
gc.collect()

This has been may weapon of last resort. More about the module at Python Central.

Leave a comment

Filed under Uncategorized