Remove schema locks in Python

2648
4
09-20-2012 09:34 AM
Status: Open
Labels (1)
DavidNagel
New Contributor II

I spend an inordinate amount of my programming time trying to deal with schema locks in Python. I often generate numerous temporary files and many end up with schema locks that I can't remove unless I quite PythonWin. Schema locks prevent me from deleting temporary files, deleting fields and renaming files. Locks are on geodatabases, shapefiles, and .vats. Sometimes I can't get anything done because I am t rying to manage schema locks. Sometimes if programming in Python I will have an ArcMap window open. Even if there is nothing in ArcMap and I never use it, the locks will not go away until I close ArcMap. Can't there be a python command that is analogous to closing ArcMap so that locks will be deleted? Schema locks are way more harmful than helpful if I calculate the amount of time I have spent trying to manage for them. In fact, I have never ever had a valid use for a schema lock or been glad it was there. They are only trouble in my world of Pytyhon programming. Thank you.

Tags (1)
4 Comments
NiklasNorrthon
Have you tried the arcpy.da cursors?

with arcpy.da.SearchCursor as cur:
    do_something_with(cur)

Here the lock is released automatically.
ChristalHigdon
Yes, please! I create temp geodatabases as scratch workspaces that I delete and recreate in my scripts and it is a huge PAIN when debugging and working through a script to have to close Pythonwin over and over every 5 minutes to clear the locks. I would like a command to clear locks on a specified geodatabase in Python.
SteveLewis

Allow a Python command to remove all locks in a FGDB, e.g., LockRemove_management_FeatureClass(FeatureClassName); LockRemove_management_ALL(FGDB  Name).

Okay, don't want to do that, how about a overwriteOutput True /OVERWRITE  so that you can actually overwrite and update the data that is being used in a service.  

Yes, this would be powerful but most of us can already delete our databases tables in enterprise DBs by a simple delete. Closing all Arc desktop apps and having to shut down the ArcGIS Server service SERVICE, finding someone who had it open two months ago, and then waiting for them to get back from vacation is not the answer. 

 

SteveLewis

I can't imagine and more needed tool that could be used by everyone other and removing LOCKS.