Select to view content in your preferred language

arcpro 2.6 arcpy fgdb lock files not clearing

3783
11
08-03-2020 12:53 PM
KennethSmith1
Emerging Contributor

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)
del res

 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?

Thanks

11 Replies
KennethSmith1
Emerging Contributor

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)
zf.close()

DonMorrison1
Frequent Contributor

Excellent idea. I was already using similar code to zip the file so it was an easy modification to filter out the .lock files.  I was expecting have have problems deleting the file geodatabase after the zip but that seems to work OK even with the .lock file.

0 Kudos