<?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 Python Toolbox - ArcGIS Pro layer locked after subsequent runs - what is stored in &amp;quot;memory&amp;quot;? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/python-toolbox-arcgis-pro-layer-locked-after/m-p/1167653#M64390</link>
    <description>&lt;P&gt;I have a python toolbox that is performing various operations on a layout. Reconfigure text elements, pan the map frame, export to PDF being the core functionality. Editing data is not involved.&lt;/P&gt;&lt;P&gt;The tool runs fine initially, but after trying a second run one of the map layers is "locked" in the layout which is causing various issues with tool execution.&lt;/P&gt;&lt;P&gt;My question is: &lt;STRONG&gt;Is Pro keeping variables, objects, classes, etc. in memory between tool runs? If so, how do I clear this so each tool run is new? Is the python process left running once the toolbox is opened?&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Additional details:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;closing Pro and running the tool again remedies the issue - lock is only applied after second run&lt;/LI&gt;&lt;LI&gt;Used del() to remove object and variables followed by gc.collect() at the end of the toolbox code execute to no avail&lt;/LI&gt;&lt;LI&gt;my IDE is VS Code - running here using the approach mentioned &lt;A href="https://www.esri.com/arcgis-blog/products/arcgis-desktop/analytics/how-to-debug-python-toolboxes-in-3-easy-steps/" target="_self"&gt;here&lt;/A&gt; does not present the issue, assuming this is due to each run being a distinct process run and closure, with nothing mainted in between&lt;/LI&gt;&lt;/UL&gt;</description>
    <pubDate>Mon, 25 Apr 2022 18:43:28 GMT</pubDate>
    <dc:creator>I_AM_ERROR</dc:creator>
    <dc:date>2022-04-25T18:43:28Z</dc:date>
    <item>
      <title>Python Toolbox - ArcGIS Pro layer locked after subsequent runs - what is stored in "memory"?</title>
      <link>https://community.esri.com/t5/python-questions/python-toolbox-arcgis-pro-layer-locked-after/m-p/1167653#M64390</link>
      <description>&lt;P&gt;I have a python toolbox that is performing various operations on a layout. Reconfigure text elements, pan the map frame, export to PDF being the core functionality. Editing data is not involved.&lt;/P&gt;&lt;P&gt;The tool runs fine initially, but after trying a second run one of the map layers is "locked" in the layout which is causing various issues with tool execution.&lt;/P&gt;&lt;P&gt;My question is: &lt;STRONG&gt;Is Pro keeping variables, objects, classes, etc. in memory between tool runs? If so, how do I clear this so each tool run is new? Is the python process left running once the toolbox is opened?&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Additional details:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;closing Pro and running the tool again remedies the issue - lock is only applied after second run&lt;/LI&gt;&lt;LI&gt;Used del() to remove object and variables followed by gc.collect() at the end of the toolbox code execute to no avail&lt;/LI&gt;&lt;LI&gt;my IDE is VS Code - running here using the approach mentioned &lt;A href="https://www.esri.com/arcgis-blog/products/arcgis-desktop/analytics/how-to-debug-python-toolboxes-in-3-easy-steps/" target="_self"&gt;here&lt;/A&gt; does not present the issue, assuming this is due to each run being a distinct process run and closure, with nothing mainted in between&lt;/LI&gt;&lt;/UL&gt;</description>
      <pubDate>Mon, 25 Apr 2022 18:43:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-toolbox-arcgis-pro-layer-locked-after/m-p/1167653#M64390</guid>
      <dc:creator>I_AM_ERROR</dc:creator>
      <dc:date>2022-04-25T18:43:28Z</dc:date>
    </item>
    <item>
      <title>Re: Python Toolbox - ArcGIS Pro layer locked after subsequent runs - what is stored in "memory"?</title>
      <link>https://community.esri.com/t5/python-questions/python-toolbox-arcgis-pro-layer-locked-after/m-p/1167685#M64392</link>
      <description>&lt;P&gt;If it is created and added to in memory, then you can use&lt;/P&gt;&lt;P&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/tool-reference/data-management/delete.htm" target="_blank"&gt;Delete (Data Management)—ArcGIS Pro | Documentation&lt;/A&gt;&lt;/P&gt;&lt;P&gt;del and gc won't occur until the script/tool is done.&lt;/P&gt;&lt;P&gt;Also, if something is being created, you can use the "overwriteOutput" environment variable&lt;/P&gt;</description>
      <pubDate>Mon, 25 Apr 2022 19:37:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-toolbox-arcgis-pro-layer-locked-after/m-p/1167685#M64392</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2022-04-25T19:37:29Z</dc:date>
    </item>
    <item>
      <title>Re: Python Toolbox - ArcGIS Pro layer locked after subsequent runs - what is stored in "memory"?</title>
      <link>https://community.esri.com/t5/python-questions/python-toolbox-arcgis-pro-layer-locked-after/m-p/1167744#M64399</link>
      <description>&lt;P&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/2.8/arcpy/mapping/migratingfrom10xarcpymapping.htm" target="_self"&gt;According to the mapping docs:&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;SPAN&gt;When you use the CURRENT keyword in the&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class=""&gt;Python&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;window with&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class=""&gt;ArcGIS Desktop&lt;/SPAN&gt;&lt;SPAN&gt;, you sometimes had to call&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class=""&gt;refreshActiveView&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;to force a screen refresh. This is no longer the case with&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class=""&gt;ArcGIS Pro&lt;/SPAN&gt;&lt;SPAN&gt;. All&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class=""&gt;arcpy.mp&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;API changes directly update&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class=""&gt;ArcGIS Pro.&lt;/SPAN&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;I haven't tried this yet in Pro, but maybe something&amp;nbsp;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/arcpy/mapping/arcgisproject-class.htm" target="_self"&gt;like&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;aprx = arcpy.mp.ArcGISProject("CURRENT")
aprx.save()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;at the end of your code to force the changes?&lt;/P&gt;</description>
      <pubDate>Mon, 25 Apr 2022 22:14:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-toolbox-arcgis-pro-layer-locked-after/m-p/1167744#M64399</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2022-04-25T22:14:47Z</dc:date>
    </item>
    <item>
      <title>Re: Python Toolbox - ArcGIS Pro layer locked after subsequent runs - what is stored in "memory"?</title>
      <link>https://community.esri.com/t5/python-questions/python-toolbox-arcgis-pro-layer-locked-after/m-p/1167747#M64400</link>
      <description>&lt;P&gt;I'm quite sure a new process is not started to run a toolbox tool, so yes, python is keeping things in memory - specially those created at the toolbox/tool class level and even in the getParameterInfo method. I've found number of places where locks are left dangling (even reported some with no resolution) and can't find a way around them other than to restart ArcGIS Pro (or restart the python kernel if running in the IDE) - good luck with this one!&lt;/P&gt;</description>
      <pubDate>Mon, 25 Apr 2022 22:22:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-toolbox-arcgis-pro-layer-locked-after/m-p/1167747#M64400</guid>
      <dc:creator>DonMorrison1</dc:creator>
      <dc:date>2022-04-25T22:22:17Z</dc:date>
    </item>
    <item>
      <title>Re: Python Toolbox - ArcGIS Pro layer locked after subsequent runs - what is stored in "memory"?</title>
      <link>https://community.esri.com/t5/python-questions/python-toolbox-arcgis-pro-layer-locked-after/m-p/1167749#M64402</link>
      <description>&lt;P&gt;I think I traced it down something being done in the update parameters method which I can't debug in IDE, either:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;arcpy.SelectLayerByAttribute_management&lt;/LI&gt;&lt;LI&gt;arcpy.ListFields&lt;/LI&gt;&lt;LI&gt;or arcpy.da.SearchCursor (used via list comprehension)&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;my guess is the cursor is being left open when used via list comprehension.&amp;nbsp;&lt;/P&gt;&lt;P&gt;obligatory - "code was inherited from someone else!"&lt;/P&gt;</description>
      <pubDate>Mon, 25 Apr 2022 22:27:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-toolbox-arcgis-pro-layer-locked-after/m-p/1167749#M64402</guid>
      <dc:creator>I_AM_ERROR</dc:creator>
      <dc:date>2022-04-25T22:27:36Z</dc:date>
    </item>
    <item>
      <title>Re: Python Toolbox - ArcGIS Pro layer locked after subsequent runs - what is stored in "memory"?</title>
      <link>https://community.esri.com/t5/python-questions/python-toolbox-arcgis-pro-layer-locked-after/m-p/1167752#M64404</link>
      <description>&lt;P&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/arcpy/data-access/searchcursor-class.htm" target="_blank" rel="noopener"&gt;SearchCursor—ArcGIS Pro | Documentation&lt;/A&gt;&lt;/P&gt;&lt;P&gt;use the "with" syntax for cursors...&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Search cursors also support with&amp;nbsp;statements to reset iteration and aid in removal of locks.&amp;nbsp;&lt;/EM&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Apr 2022 22:31:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-toolbox-arcgis-pro-layer-locked-after/m-p/1167752#M64404</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2022-04-25T22:31:01Z</dc:date>
    </item>
    <item>
      <title>Re: Python Toolbox - ArcGIS Pro layer locked after subsequent runs - what is stored in "memory"?</title>
      <link>https://community.esri.com/t5/python-questions/python-toolbox-arcgis-pro-layer-locked-after/m-p/1167753#M64405</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;P&gt;my guess is the cursor is being left open when used via list comprehension.&amp;nbsp;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;That could be an important detail - cursors are usually called using `with` to ensure the entry and exit get hit. Perhaps it's dangling if not closed properly? Curious to see if that caused it.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Apr 2022 22:31:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-toolbox-arcgis-pro-layer-locked-after/m-p/1167753#M64405</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2022-04-25T22:31:42Z</dc:date>
    </item>
    <item>
      <title>Re: Python Toolbox - ArcGIS Pro layer locked after subsequent runs - what is stored in "memory"?</title>
      <link>https://community.esri.com/t5/python-questions/python-toolbox-arcgis-pro-layer-locked-after/m-p/1167756#M64406</link>
      <description>&lt;P&gt;It was - well, it's currently commented out and execution is running and not leaving layer locks in the map anymore. If I re-enable I'll use "with" and report back.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Apr 2022 22:46:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-toolbox-arcgis-pro-layer-locked-after/m-p/1167756#M64406</guid>
      <dc:creator>I_AM_ERROR</dc:creator>
      <dc:date>2022-04-25T22:46:35Z</dc:date>
    </item>
    <item>
      <title>Re: Python Toolbox - ArcGIS Pro layer locked after subsequent runs - what is stored in "memory"?</title>
      <link>https://community.esri.com/t5/python-questions/python-toolbox-arcgis-pro-layer-locked-after/m-p/1543420#M72952</link>
      <description>&lt;P&gt;I have a similar issue. I have a python toolbox tool that downloads multidimensional rasters via API calls. Then it merges those rasters using the merge multidimensional rasters tool. If I then try to run the tool again, intending to overwrite everything,&amp;nbsp; the raster download fails because it can't overwrite the existing rasters which are "being&amp;nbsp; used by another process". The other process is the merge operation (re-running the tool worked fine before I added the merge) which is long finished at that point.&amp;nbsp; The only thing that seems to release the lock is closing and opening ArcGIS Pro. I don't know how I could use a "with" statement for merging a raster.&lt;BR /&gt;I tried adding&amp;nbsp;arcpy.env.overwriteOutput = True to my script but that didn't help.&lt;BR /&gt;Did you ever find a way of getting rid of the lock?&lt;/P&gt;</description>
      <pubDate>Fri, 27 Sep 2024 14:50:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-toolbox-arcgis-pro-layer-locked-after/m-p/1543420#M72952</guid>
      <dc:creator>SarahGe</dc:creator>
      <dc:date>2024-09-27T14:50:51Z</dc:date>
    </item>
  </channel>
</rss>

