arcpy.da.Describe locks geodatabase

710
2
Jump to solution
11-29-2022 01:55 PM
by Anonymous User
Not applicable

arcpy.da.Describe seems to put a lock on the layer in a geodatabase. The only way to remove it seems to be closing the script. This doesn't work for me, because I need to gather info from the Describe function, and then depending on the results, move / delete the geodatabase in the same script. I tried deleting the results from the Describe function after I no longer need them, but it's just a dictionary, so it doesn't help.

Here's the basics:

aprx = arcpy.mp.ArcGISProject(path)
m = aprx.listMaps()[0]
lyrs = m.listLayers()
lyr = lyrs[0]

info = arcpy.da.Describe(lyr)   # now there's a lock on the feature class that won't go away

# do some other fancy stuff here...

arcpy.management.Delete(gdb_path)  # fails because there's a lock on the fc

 

0 Kudos
1 Solution

Accepted Solutions
by Anonymous User
Not applicable

Found a solution: use a path as the input, instead of a mapping layer object. ALSO, use arcpy.Describe instead of arcpy.da.Describe. Seems a little silly, but it works...

 

describe_fix.PNG

View solution in original post

0 Kudos
2 Replies
by Anonymous User
Not applicable

Found a solution: use a path as the input, instead of a mapping layer object. ALSO, use arcpy.Describe instead of arcpy.da.Describe. Seems a little silly, but it works...

 

describe_fix.PNG

0 Kudos
isburns
New Contributor III

I had a similar issue where using the arcpy.da module was creating a lock on my file geodatabase. I see you worked around your problem using arcpy.Describe(), but I also discovered you can use arcpy.da.Describe() so long as you use a path as the argument instead of the Layer object and also call another function that seems to force the reset, which in my case was arcpy.management.GetCount().

There seem to be two bugs here. One, when you use the Layer object as an argument to a function like Describe(), whether it's the da module or not, a lock is created that cannot be released. Two, when you use the arcpy.da module, a lock is created that can only be released if using paths to the data since using Layer objects also creates locks. See my post with additional code samples demonstrating the issues.

0 Kudos