<?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 Re: Residual locks on aprx files after list iteration. in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/residual-locks-on-aprx-files-after-list-iteration/m-p/1602451#M94626</link>
    <description>&lt;P&gt;a related thread to locks and arcpy.mapping which may be of interest&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.esri.com/t5/arcgis-pro-questions/arcpy-mp-arcgisproject-aprx-lock-issue/m-p/1408692#M81738" target="_blank" rel="noopener"&gt;arcpy.mp.ArcGISProject .aprx lock issue&lt;/A&gt;&lt;/P&gt;&lt;P&gt;I tracked down the enhancement request&lt;/P&gt;&lt;P&gt;&lt;A href="https://support.esri.com/en-us/enhancement/when-using-save-as-on-a-project-a-new-aprx-is-made-refe-enh-000121601" target="_blank"&gt;ENH-000121601 for ArcGIS Pro&lt;/A&gt;&lt;/P&gt;&lt;P&gt;apparently "in Product Plan"&lt;/P&gt;&lt;P&gt;and a related "Idea" with a protracted discussion or python and aprx stuff&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.esri.com/t5/arcgis-pro-ideas/save-project-as-creating-more-than-just-the-aprx/idi-p/1195131" target="_blank"&gt;Save Project As, Creating more than just the APRX - Esri Community&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 03 Apr 2025 18:08:44 GMT</pubDate>
    <dc:creator>DanPatterson</dc:creator>
    <dc:date>2025-04-03T18:08:44Z</dc:date>
    <item>
      <title>Residual locks on aprx files after list iteration.</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/residual-locks-on-aprx-files-after-list-iteration/m-p/1602363#M94620</link>
      <description>&lt;P&gt;I'm having an odd issue with residual locks on aprx files when I interact with them via iteration through a list of names. Specifically, the first file that I reference ends up with a hanging lock but the others do not.&lt;BR /&gt;&lt;BR /&gt;I've queried with locals(), and Python does not think it has any hanging references left to an open arcpy object. Here is the code (with paths and files anonymized):&lt;/P&gt;&lt;LI-CODE lang="c"&gt;objDict = locals().copy()
prjPath ="C:/Pydata/thisproject/testdir/"
prjs = ["project1.aprx", "project2.aprx","project3.aprx", "project4.aprx"]
shpPath = "C:/Pydata/thisproject/subproject/outputs/"
boundaryPath = "C:/Pydata/thisproject/GIScovs/boundaryshapefile/"

mths = ["jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec"]
stages = ["C4","C3","C2","C1"]
for idx, prjName in enumerate(prjs):
     fullname = prjPath + prjName
     ArcProject = arcpy.mp.ArcGISProject(fullname) #open the required project
     workingmap = ArcProject.listMaps()[0] # open map to add shapefiles
     stg = stages[idx] #get the relevant stage
     #by iterating the month list in reverse order, placement within the project aligns with desired pattern
     for mth in reversed(mths):
          shpStr = stg + "_" + mth + "_val"
          shpName = shpPath + shpStr
          if arcpy.Exists(shpName): # make sure the desired file exists before adding in order to trap errors related to sparse data
               workingmap.addDataFromPath(shpName)
           else:
               print("shape " + shpName + " not found")

     #next add the desired boundary file:
     #this is the name of the desired layer
     boundaryLyrPath = "C:/Pydata/GIScovs/boundary.lyrx"
     boundaryLyr = arcpy.mp.LayerFile(boundaryLyrPath)
     workingmap.addLayer(boundaryLyr)
     #save the project
     ArcProject.save()
     
     #DELETE ALL REFERENCES TO ARCPY OBJECTS
     del boundaryLyr
     del workingmap
     del ArcProject
newObjDict = locals().copy()
for listitem in newObjDict:
#print active objects added by this code block
if listitem not in objDict:
     print(listitem)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The printout from comparing the dictionaries gives:&lt;/P&gt;&lt;PRE&gt;prjPath&lt;BR /&gt;prjs&lt;BR /&gt;shpPath
boundaryPath
mths
stages
idx
stg
mth
shpStr
shpName
boundaryLyrPath&lt;/PRE&gt;&lt;P&gt;All of these are pure Python objects, none are ArcPy references.&lt;BR /&gt;&lt;BR /&gt;When I run this, "project1.aprx" (the first item in the projects list) ends up with a hanging lock such that in the next block of code that I run it cannot be saved (it's read-only). The others do not have the same issue. I'm at a loss, but maybe I'm missing something obvious?&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Thanks in advance for any thoughts.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Apr 2025 15:18:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/residual-locks-on-aprx-files-after-list-iteration/m-p/1602363#M94620</guid>
      <dc:creator>beachcomber_0972</dc:creator>
      <dc:date>2025-04-03T15:18:07Z</dc:date>
    </item>
    <item>
      <title>Re: Residual locks on aprx files after list iteration.</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/residual-locks-on-aprx-files-after-list-iteration/m-p/1602451#M94626</link>
      <description>&lt;P&gt;a related thread to locks and arcpy.mapping which may be of interest&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.esri.com/t5/arcgis-pro-questions/arcpy-mp-arcgisproject-aprx-lock-issue/m-p/1408692#M81738" target="_blank" rel="noopener"&gt;arcpy.mp.ArcGISProject .aprx lock issue&lt;/A&gt;&lt;/P&gt;&lt;P&gt;I tracked down the enhancement request&lt;/P&gt;&lt;P&gt;&lt;A href="https://support.esri.com/en-us/enhancement/when-using-save-as-on-a-project-a-new-aprx-is-made-refe-enh-000121601" target="_blank"&gt;ENH-000121601 for ArcGIS Pro&lt;/A&gt;&lt;/P&gt;&lt;P&gt;apparently "in Product Plan"&lt;/P&gt;&lt;P&gt;and a related "Idea" with a protracted discussion or python and aprx stuff&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.esri.com/t5/arcgis-pro-ideas/save-project-as-creating-more-than-just-the-aprx/idi-p/1195131" target="_blank"&gt;Save Project As, Creating more than just the APRX - Esri Community&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Apr 2025 18:08:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/residual-locks-on-aprx-files-after-list-iteration/m-p/1602451#M94626</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2025-04-03T18:08:44Z</dc:date>
    </item>
    <item>
      <title>Re: Residual locks on aprx files after list iteration.</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/residual-locks-on-aprx-files-after-list-iteration/m-p/1602461#M94629</link>
      <description>&lt;P&gt;Thanks for the info. I'd know ArcPy locks sometimes got a little wonky, I just don't know how to get around this particular one. I'm not quite sure how this got marked as 'solved' because it's still not.&lt;BR /&gt;&lt;BR /&gt;Anyhow, I selectively commented out actions in the script I posted, and the issue arises from lines 18 and 19- either from Arcpy.exists or (more likely) workingmap.addDataFromPath. I don't see any easy way around using those two commands to do what I want, though.&lt;/P&gt;</description>
      <pubDate>Thu, 03 Apr 2025 18:20:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/residual-locks-on-aprx-files-after-list-iteration/m-p/1602461#M94629</guid>
      <dc:creator>beachcomber_0972</dc:creator>
      <dc:date>2025-04-03T18:20:41Z</dc:date>
    </item>
  </channel>
</rss>

