arcpro 2.6 arcpy fgdb lock files not clearing

2772
10
08-03-2020 12:53 PM
KennethSmith1
New Contributor II

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

10 Replies
DanPatterson
MVP Esteemed Contributor

If this worked in 2.5, I would report to Technical Support.

Arcpy can't clear locks... it is well requested item


... sort of retired...
0 Kudos
CooperLogan
Esri Contributor

Hi Kenneth Smith

It sounds like this issue has been reported as a bug with 2.6:

[ BUG-000133976: Unexpected behavior creating file geodatabases at 2.6 ]

Hope this helps!

Cooper

0 Kudos
DonMorrison1
Occasional Contributor III

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.

0 Kudos
DanPatterson
MVP Esteemed Contributor

BUG-000133976: Unexpected behavior occurs when creating file geodat.. 

no alternate solution provided


... sort of retired...
0 Kudos
CooperLogan
Esri Contributor

Hi Don,

One workaround that allowed some users to circumvent the problem is to add the following line right before the script errors out:

  • arcpy.ClearWorkspaceCache_management()

I hope this helps!

Cooper

Don Morrison

MarcoBoeringa
MVP Regular Contributor

Cooper Logan‌,

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."

0 Kudos
JustinKraemer
New Contributor II

@MarcoBoeringa, I saw your reply, but decided to give it a try anyway, and found it worked! Mine is a file geodatabase. Just thought I should share

0 Kudos
MarcoBoeringa
MVP Regular Contributor

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

0 Kudos
KennethSmith1
New Contributor II

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()