<?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: exportToSDDraft leaves aprx file locked in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/exporttosddraft-leaves-aprx-file-locked/m-p/805459#M2267</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The ESRI problem tracking number is&amp;nbsp;&lt;SPAN style="color: #222222; background-color: #ffffff; font-size: small;"&gt;BUG-000128820&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 20 Feb 2020 19:54:37 GMT</pubDate>
    <dc:creator>DonMorrison1</dc:creator>
    <dc:date>2020-02-20T19:54:37Z</dc:date>
    <item>
      <title>exportToSDDraft leaves aprx file locked</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/exporttosddraft-leaves-aprx-file-locked/m-p/805452#M2260</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm developing a python app that makes heavy use of the ArcGIS API for Python and running into a problem where it appears that when I run exportToSDDraft, a lock is left on the aprx file that I used to create the draft. This causes a failure downstream when I try to reopen the file (or delete it). Any suggestions on how to release this lock or is there an alternative to exportToSDDraft (Python 3).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is the error message I get when I try to delete the file is os.remove. I confirmed that it is actually the same process that is holding the lock - not a different process as&amp;nbsp; the message states.&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'E:\\ROW_as_habitat\\projects\\test.aprx'&lt;/PRE&gt;&lt;P&gt;Here is the error when I do the delete with arcpy.DeleteManagement&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;ExecuteError: ERROR 000601: Cannot delete E:\ROW_as_habitat\projects\test.aprx. May be locked by another application.
Failed to execute (Delete).&lt;/PRE&gt;&lt;P&gt;I boiled down the script as far as I could to recreate the problem. When I remove the line with exportToSDDraft, there is no lock on the aprx file and the script completes successfully.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import os
import arcpy

blank_project_fn = os.path.abspath('config/templates/blank_project.aprx')
project_fn = os.path.normpath('E:/ROW_as_habitat/projects/test.aprx')
sd_draft_fn = os.path.normpath('E:/ROW_as_habitat/sd_drafts/test.sddraft')
connection_file = os.path.normpath('E:/ROW_as_habitat/conn3.ags')
layer_fn = os.path.normpath('E:/ROW_as_habitat/org_layer_files/Ameren_Sites.lyrx')

def create_project ():
 # Make a copy of the blank temlate project
 template_aprx = arcpy.mp.ArcGISProject(blank_project_fn)
 template_aprx.saveACopy(project_fn)
 del (template_aprx)
 
 # Open the new copy and make changes
 aprx_obj = arcpy.mp.ArcGISProject(project_fn)
 m_map = aprx_obj.listMaps()[0]
 m_map.addLayer(arcpy.mp.LayerFile(layer_fn), "BOTTOM")
 aprx_obj.save()
 
 del (m_map)
 del (aprx_obj)

def create_sd_draft ():
 aprx_obj = arcpy.mp.ArcGISProject(project_fn) # THIS IS THE FILE THE STAYS LOCKED
 aprx_map = aprx_obj.listMaps()[0]
 # Create MapServiceDraft and set service properties
 service_draft = arcpy.sharing.CreateSharingDraft("STANDALONE_SERVER", "MAP_SERVICE", 'test', aprx_map)
 service_draft.targetServer = connection_file
 &lt;STRONG style="color: #ff0000; "&gt;service_draft.exportToSDDraft(sd_draft_fn) # THIS APPEARS TO LEAVE THE APRX FILE LOCKED&lt;/STRONG&gt;
 del (aprx_map)
 del (aprx_obj)
 del (service_draft)
 
def delete_project ():
 print (str(os.getpid()))
 if arcpy.Exists(project_fn):
  arcpy.Delete_management(project_fn)

  
if __name__ == '__main__':
 delete_project ()
 create_project ()
 create_sd_draft ()
 delete_project () # TEST FAILS HERE WHEN exportToSDDRaft is not commented out&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 16:56:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/exporttosddraft-leaves-aprx-file-locked/m-p/805452#M2260</guid>
      <dc:creator>DonMorrison1</dc:creator>
      <dc:date>2021-12-12T16:56:19Z</dc:date>
    </item>
    <item>
      <title>Re: exportToSDDraft leaves aprx file locked</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/exporttosddraft-leaves-aprx-file-locked/m-p/805453#M2261</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This has been logged as a bug. No word on when and if it will be fixed.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 03 May 2019 12:50:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/exporttosddraft-leaves-aprx-file-locked/m-p/805453#M2261</guid>
      <dc:creator>DonMorrison1</dc:creator>
      <dc:date>2019-05-03T12:50:36Z</dc:date>
    </item>
    <item>
      <title>Re: exportToSDDraft leaves aprx file locked</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/exporttosddraft-leaves-aprx-file-locked/m-p/805454#M2262</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Do you have a bug number that you can share? I'm running up against this same issue.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 03 Feb 2020 20:47:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/exporttosddraft-leaves-aprx-file-locked/m-p/805454#M2262</guid>
      <dc:creator>ScottDavis</dc:creator>
      <dc:date>2020-02-03T20:47:22Z</dc:date>
    </item>
    <item>
      <title>Re: exportToSDDraft leaves aprx file locked</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/exporttosddraft-leaves-aprx-file-locked/m-p/805455#M2263</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sorry but I do not. I requested a bug number a couple of times but got no response so I finally gave up. I'll give it another try and let you know if I get anything.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 04 Feb 2020 11:06:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/exporttosddraft-leaves-aprx-file-locked/m-p/805455#M2263</guid>
      <dc:creator>DonMorrison1</dc:creator>
      <dc:date>2020-02-04T11:06:14Z</dc:date>
    </item>
    <item>
      <title>Re: exportToSDDraft leaves aprx file locked</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/exporttosddraft-leaves-aprx-file-locked/m-p/805456#M2264</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;A href="https://community.esri.com/migrated-users/359537" target="_blank"&gt;Don Morrison&lt;/A&gt;‌ did you try switching the order of the deletes?&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;current
del (aprx_map)
 del (aprx_obj)
 del (service_draft)

&lt;PRE class="lia-code-sample line-numbers language-none"&gt;del (service_draft)
del (aprx_map)
del (aprx_obj)

Just trying to think of what would have a 'grasp' on things in the order that they were created.
 &lt;/PRE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 09:23:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/exporttosddraft-leaves-aprx-file-locked/m-p/805456#M2264</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2021-12-12T09:23:15Z</dc:date>
    </item>
    <item>
      <title>Re: exportToSDDraft leaves aprx file locked</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/exporttosddraft-leaves-aprx-file-locked/m-p/805457#M2265</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think I tried every combination - although it was quite a while ago when I did this.&amp;nbsp; ESRI acknowledged that there is a bug so I gave up on it.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 04 Feb 2020 18:40:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/exporttosddraft-leaves-aprx-file-locked/m-p/805457#M2265</guid>
      <dc:creator>DonMorrison1</dc:creator>
      <dc:date>2020-02-04T18:40:56Z</dc:date>
    </item>
    <item>
      <title>Re: exportToSDDraft leaves aprx file locked</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/exporttosddraft-leaves-aprx-file-locked/m-p/805458#M2266</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;sadly&amp;nbsp;&lt;STRONG style="color: #ff0000; border: 0px; font-weight: bold; font-size: 14px;"&gt;exportToSDDraft&lt;/STRONG&gt; only pops up two unrelated threads on the support site. It would be nice to have a current bug list if it was an acknowledge issue.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 04 Feb 2020 20:14:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/exporttosddraft-leaves-aprx-file-locked/m-p/805458#M2266</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2020-02-04T20:14:40Z</dc:date>
    </item>
    <item>
      <title>Re: exportToSDDraft leaves aprx file locked</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/exporttosddraft-leaves-aprx-file-locked/m-p/805459#M2267</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The ESRI problem tracking number is&amp;nbsp;&lt;SPAN style="color: #222222; background-color: #ffffff; font-size: small;"&gt;BUG-000128820&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 20 Feb 2020 19:54:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/exporttosddraft-leaves-aprx-file-locked/m-p/805459#M2267</guid>
      <dc:creator>DonMorrison1</dc:creator>
      <dc:date>2020-02-20T19:54:37Z</dc:date>
    </item>
  </channel>
</rss>

