Select to view content in your preferred language

ArcGIS Pro 3.0.0 will not delete scratch.gdb at end of script, whereas ArcGIS Pro 2.9.x will...?

833
1
07-12-2022 12:49 PM
N_W_S_E
Occasional Contributor

I just upgraded to ArcGIS Pro 3.0 and was trying to run my script that worked completely in ArcGIS Pro 2.9.x.

Here is a code snippet for context:

# start of script to set variables for context
desktop = os.path.join(os.path.join(os.environ["USERPROFILE"]), "Desktop")
arcpy.env.scratchWorkspace = desktop
scratchGDB = arcpy.env.scratchGDB

# end of script
arcpy.env.workspace = scratchGDB
for scratch_fc in arcpy.ListFeatureClasses():
    arcpy.Delete_management(scratch_fc)
arcpy.Delete_management(scratchGDB)

# alternative attempt
arcpy.env.workspace = scratchGDB
for scratch_fc in arcpy.ListFeatureClasses():
    if arcpy.Exists(scratch_fc):
        arcpy.Delete_management(scratch_fc)
arcpy.ResetEnvironments()
if arcpy.Exists(arcpy.env.scratchWorkspace):
    arcpy.Delete_management(scratchGDB)

However, I am now getting this error: 

ERROR 000601: Cannot delete C:\Users\name\Desktop\scratch.gdb. May be locked by another application.

To try and fix this error, I attempted to not use a scratch.gdb and store the temp layers in r"memory", however, because I am using tools such as Project, etc, I get an error stating that the layers cannot be stored in memory.

I checked the scratch.gdb folder on my desktop and there are no LOCK files after the script is executed. During the runtime, I do get LOCK files for the temp layers that are created, but these get removed when I run:

# clear table of contents in map
for toc_layer in map.listLayers():
    if toc_layer.name == "":
        map.removeLayer(toc_layer)

 At this point, the TOC is empty and the no layers from scratch.gdb are being used. 

I even attempted to run a time delay using:

import time

...

time.sleep(60)

To see if perhaps the script was running faster than my ArcGIS Pro could handle, however, after the time delay, there is still an error in trying to delete scratch.gdb.

Does anyone have any insights or solutions?

Thank you in advance

0 Kudos
1 Reply
DanPatterson
MVP Esteemed Contributor

were there any differences in your setup for the arcpy.env settings for scratch geodatabase and/or scratch workspace?

Scratch GDB (Environment setting)—ArcGIS Pro | Documentation


... sort of retired...
0 Kudos