<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic ArcGIS Pro 3.0.0 will not delete scratch.gdb at end of script, whereas ArcGIS Pro 2.9.x will...? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/arcgis-pro-3-0-0-will-not-delete-scratch-gdb-at/m-p/1191681#M64997</link>
    <description>&lt;P&gt;I just upgraded to ArcGIS Pro 3.0 and was trying to run my script that worked completely in ArcGIS Pro 2.9.x.&lt;/P&gt;&lt;P&gt;Here is a code snippet for context:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# 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)&lt;/LI-CODE&gt;&lt;P&gt;However, I am now getting this error:&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;ERROR 000601: Cannot delete C:\Users\name\Desktop\scratch.gdb. May be locked by another application.&lt;/LI-CODE&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;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:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# clear table of contents in map
for toc_layer in map.listLayers():
    if toc_layer.name == "":
        map.removeLayer(toc_layer)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;At this point, the TOC is empty and the no layers from scratch.gdb are being used.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I even attempted to run a time delay using:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import time

...

time.sleep(60)&lt;/LI-CODE&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;Does anyone have any insights or solutions?&lt;/P&gt;&lt;P&gt;Thank you in advance&lt;/P&gt;</description>
    <pubDate>Tue, 12 Jul 2022 19:49:53 GMT</pubDate>
    <dc:creator>N_W_S_E</dc:creator>
    <dc:date>2022-07-12T19:49:53Z</dc:date>
    <item>
      <title>ArcGIS Pro 3.0.0 will not delete scratch.gdb at end of script, whereas ArcGIS Pro 2.9.x will...?</title>
      <link>https://community.esri.com/t5/python-questions/arcgis-pro-3-0-0-will-not-delete-scratch-gdb-at/m-p/1191681#M64997</link>
      <description>&lt;P&gt;I just upgraded to ArcGIS Pro 3.0 and was trying to run my script that worked completely in ArcGIS Pro 2.9.x.&lt;/P&gt;&lt;P&gt;Here is a code snippet for context:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# 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)&lt;/LI-CODE&gt;&lt;P&gt;However, I am now getting this error:&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;ERROR 000601: Cannot delete C:\Users\name\Desktop\scratch.gdb. May be locked by another application.&lt;/LI-CODE&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;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:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# clear table of contents in map
for toc_layer in map.listLayers():
    if toc_layer.name == "":
        map.removeLayer(toc_layer)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;At this point, the TOC is empty and the no layers from scratch.gdb are being used.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I even attempted to run a time delay using:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import time

...

time.sleep(60)&lt;/LI-CODE&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;Does anyone have any insights or solutions?&lt;/P&gt;&lt;P&gt;Thank you in advance&lt;/P&gt;</description>
      <pubDate>Tue, 12 Jul 2022 19:49:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcgis-pro-3-0-0-will-not-delete-scratch-gdb-at/m-p/1191681#M64997</guid>
      <dc:creator>N_W_S_E</dc:creator>
      <dc:date>2022-07-12T19:49:53Z</dc:date>
    </item>
    <item>
      <title>Re: ArcGIS Pro 3.0.0 will not delete scratch.gdb at end of script, whereas ArcGIS Pro 2.9.x will...?</title>
      <link>https://community.esri.com/t5/python-questions/arcgis-pro-3-0-0-will-not-delete-scratch-gdb-at/m-p/1191718#M64999</link>
      <description>&lt;P&gt;were there any differences in your setup for the arcpy.env settings for scratch geodatabase and/or scratch workspace?&lt;/P&gt;&lt;P&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/tool-reference/environment-settings/scratch-gdb.htm" target="_blank"&gt;Scratch GDB (Environment setting)—ArcGIS Pro | Documentation&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Jul 2022 22:03:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcgis-pro-3-0-0-will-not-delete-scratch-gdb-at/m-p/1191718#M64999</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2022-07-12T22:03:56Z</dc:date>
    </item>
  </channel>
</rss>

