Select to view content in your preferred language

File lock on file geodatabase when running arcpy in command line

114
1
Jump to solution
a week ago
ChaceCarpenter
Occasional Contributor

Hi I am running a script in the command line with the hope of sending it to task scheduler at some point. I'm getting a lock error when I try to zip a file geodatabase. I don't get this error when I run the script directly within arcpro's notebook. Is there any solution for this and a explanation of why.  

The line of code im using to zip the file geodatabase can be seen below

print('#Zipping file geodatabase to be sent to AGOL')
result = shutil.make_archive(r'ElectricDataToAGOL',format='zip',base_dir='ElectricDataToAGOL.gdb')
del result

This code works without any locks when I run it in a Arcpro notebook

The error message I get can be seen below

Traceback (most recent call last):
File "C:\Scripts_and_Projects\Archive\Modules\ElectricDataToAGOL.py", line 75, in <module>
result = shutil.make_archive(r'ElectricDataToAGOL',format='zip',base_dir='ElectricDataToAGOL.gdb')
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\Lib\shutil.py", line 1165, in make_archive
filename = func(base_name, base_dir, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\Lib\shutil.py", line 1046, in _make_zipfile
zf.write(path, arcname)
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\Lib\zipfile.py", line 1814, in write
with open(filename, "rb") as src, self.open(zinfo, 'w') as dest:
^^^^^^^^^^^^^^^^^^^^
PermissionError: [Errno 13] Permission denied: 'ElectricDataToAGOL.gdb\\_gdb.GIS-ENT-SQL1.11216.5248.sr.lock'

0 Kudos
1 Solution

Accepted Solutions
ChaceCarpenter
Occasional Contributor

The solution is to clear the cache of the workspace by using arcpy.management.ClearWorkspaceCache()

View solution in original post

0 Kudos
1 Reply
ChaceCarpenter
Occasional Contributor

The solution is to clear the cache of the workspace by using arcpy.management.ClearWorkspaceCache()

0 Kudos