8

I'm trying to find a way to determine whether a feature class is locked before trying to alter it.

In one database I want to remove a feature class completely, and in another I want to add extra fields. I can't do either if they're locked.

I was expecting to find something in arcpy.Describe() but haven't found anything. Something like

if arcpy.Describe(myFC).isLocked:
 print "Can't proceed - feature class is locked"
else:
 arcpy.Delete_management(myFC)

Is there a way to check feature class locks using arcpy?

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Jul 18, 2016 at 0:22

2 Answers 2

12

Found it - I was using incorrect terminology in my searches.

There is a tool called Test Schema Lock which will return True or False based on whether a lock can be applied or not. So my code would be:

if not arcpy.TestSchemaLock(myFC):
 print "Can't proceed - feature class is locked"
else:
 arcpy.Delete_management(myFC)

Because it returns True if the feature class isn't locked (i.e. a lock can be applied), an if not needs to be used to find where it returns False (it is locked).

answered Jul 18, 2016 at 0:32
2
  • 1
    Does this work on the entire gdb as well as individual feature classes? What about shapefiles? Commented Apr 19, 2017 at 13:57
  • 1
    @CraigT it's only 4 lines, have you tried it? I suspect it will work for shapefiles as well, but I haven't tried. I don't know about entire gdb - locks are usually per feature class so I'm not sure if a gdb reports it is locked. You could loop through each feature class to determine which is locked and which isn't Commented Apr 19, 2017 at 14:05
1

This syntax is outdated now.

You can use arcpy.testSchemaLock() instead.

Link to Doc. https://pro.arcgis.com/en/pro-app/latest/arcpy/functions/testschemalock.htm

answered Sep 8, 2023 at 19:02
1
  • What syntax is outdated? Your suggested solution is the same as the accepted answer Commented Sep 8, 2023 at 19:53

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.