I recently upgraded to Arcpro 2.6 and am having issues with an ArcPy script that exported data to a file geodatabase and then zipped that fgdb.
res=arcpy.FeatureClassToFeatureClass_conversion(in_features=inFeature, out_path=I10_fgdb, out_name=FC)
shutil.make_archive(fgdbPath, 'zip', ZipPath,fgdb)
This worked just fine in 2.5.X, however, after the upgrade, the lock file in the FGDB directory is not going away and that causes the zip to fail. How can I get ArcPy to clear the lockfile in a FGDB?
Hi Cooper - do you know if there is a way to circumvent this problem? I have a number of critical scripts that are broken due this bug. I'm willing to go in and add some code if necessary. It looks to me like the only way to get rid of that lock file is to end the python script's process, but to do that in the middle of the script is really not feasible.
One workaround that allowed some users to circumvent the problem is to add the following line right before the script errors out:
I hope this helps!
I am confused. This issue is about File Geodatabases being kept locked. The workaround you suggested shouldn't work according to this Help page, as arcpy.ClearWorkspaceCache_management() is only supposed to do anything for Enterprise Geodatabases, not File Geodatabases. The Help is quite adamant on that aspect:
"This tool only works with enterprise geodatabase workspaces."
I also wonder if this issue is actually being worked on? This is a quite hideous issue, causing significant problems for arcpy / Python development. I have reported a similar issue to the Dutch branch of ESRI based on a custom arcpy Python geoprocessing tool of mine that suddenly started failing going from Pro 2.4.3 to Pro 2.5, and the issue was also caused by left over *.lock files in a File Geodatabase folder, that weren't being cleaned up in Pro 2.5, while not an issue and being cleared properly in Pro 2.4.3.
It is registered as:
BUG-000131154 Fgdb locking behavior is different in ArcGIS Pro 2.5 to ArcGIS Pro 2.4.3 for copying styles
My major issue was I was trying to zip the fgdb and it was causing it to break when using the shutil.make_archive. I coded around it in the following way by avoiding the lock files:
# shutil.make_archive(fgdbPath, 'zip', ZipPath,fgdb) -- this breaks with this bug
zf = zipfile.ZipFile(FGDBArchive, "w")
for dirname, subdirs, files in os.walk(fgdbPath):
for filename in files:
zfilename, zfileext = os.path.splitext(filename)
if (zfileext != ".lock"):
zf.write(os.path.join(fgdbPath, filename), os.path.join(fgdb, filename), zipfile.ZIP_DEFLATED)