<?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: How do you close raster files in Arcpy created by .save()? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/how-do-you-close-raster-files-in-arcpy-created-by/m-p/406152#M31965</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You code would go a long way... can you share it? (with proper syntax formatting as well)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 07 Feb 2017 21:53:56 GMT</pubDate>
    <dc:creator>DanPatterson_Retired</dc:creator>
    <dc:date>2017-02-07T21:53:56Z</dc:date>
    <item>
      <title>How do you close raster files in Arcpy created by .save()?</title>
      <link>https://community.esri.com/t5/python-questions/how-do-you-close-raster-files-in-arcpy-created-by/m-p/406151#M31964</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello. I have just starting using Arcpy on Python2.7&amp;nbsp;and I am saving raster&amp;nbsp;datasets&amp;nbsp;as tiff files using .save() on raster objects as explained here (&lt;A href="http://pro.arcgis.com/en/pro-app/arcpy/classes/raster-object.htm"&gt;http://pro.arcgis.com/en/pro-app/arcpy/classes/raster-object.htm&lt;/A&gt;).&amp;nbsp; I am saving&amp;nbsp;enough that I am encountering memory issues half way through my code, causing it to crash.&amp;nbsp; I believe python is not closing these files after it&amp;nbsp;saves them.&amp;nbsp; I can use psutil to view the files which are currently&amp;nbsp;opened&amp;nbsp;by python and&amp;nbsp;I see that they are all still open, and&amp;nbsp;windows also&amp;nbsp;tells me they are still 'open in pythonw' if I try to delete them.&amp;nbsp; I have tried assigning the command itself&amp;nbsp;to a variable and deleting this, but it does not close the file (even after an explicit garbage collection call), nor does it close the file if you delete the raster variable itself.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How do you close a raster which has been created/opened by the .save() command without closing python?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 07 Feb 2017 16:53:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-do-you-close-raster-files-in-arcpy-created-by/m-p/406151#M31964</guid>
      <dc:creator>AlexWebb</dc:creator>
      <dc:date>2017-02-07T16:53:10Z</dc:date>
    </item>
    <item>
      <title>Re: How do you close raster files in Arcpy created by .save()?</title>
      <link>https://community.esri.com/t5/python-questions/how-do-you-close-raster-files-in-arcpy-created-by/m-p/406152#M31965</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You code would go a long way... can you share it? (with proper syntax formatting as well)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 07 Feb 2017 21:53:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-do-you-close-raster-files-in-arcpy-created-by/m-p/406152#M31965</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2017-02-07T21:53:56Z</dc:date>
    </item>
    <item>
      <title>Re: How do you close raster files in Arcpy created by .save()?</title>
      <link>https://community.esri.com/t5/python-questions/how-do-you-close-raster-files-in-arcpy-created-by/m-p/406153#M31966</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm having this problem too. Here is a piece of example code representative of what I'm trying to do.&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;from arcpy import sa
raster_elevation = sa.Raster("elevation")

raster_slope = sa.Slope(raster_elevation, "DEGREE")

raster_slope.save("slope")‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;When I try to delete or move the files referenced above (after the script is finished) from my file browser, I get the error, "The action can't be completed because the file is open in pythonw.exe". This happens to both raster files. Closing the Python shell completely removes the hold on the files, but I would like to be able to manipulate the files (from outside arcpy) after the script is finished and before I close the shell.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for your help!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 18:28:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-do-you-close-raster-files-in-arcpy-created-by/m-p/406153#M31966</guid>
      <dc:creator>TylerJohnson7</dc:creator>
      <dc:date>2021-12-11T18:28:14Z</dc:date>
    </item>
    <item>
      <title>Re: How do you close raster files in Arcpy created by .save()?</title>
      <link>https://community.esri.com/t5/python-questions/how-do-you-close-raster-files-in-arcpy-created-by/m-p/406154#M31967</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;finicky arcpy is... in theory, &lt;/P&gt;&lt;PRE class="language-python line-numbers"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;del&lt;/SPAN&gt; raster_elevation&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; raster_slope&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;and for good measure&lt;/P&gt;&lt;PRE class="language-python line-numbers"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;del&lt;/SPAN&gt; arcpy&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;should remove the reference from python, but there is no guarantee&lt;/P&gt;&lt;P&gt;sometimes what I do, is have two instances of the same script open in two different IDEs and I just kill the one that was running the script and carry on in the other one.&amp;nbsp; A bit of overkill, but separate python instances tend to play nice if arcpy gets too hungry.&lt;/P&gt;&lt;P&gt;And by the way... if arcmap is open, the lock can remain, so I rarely have it open unless I have to see the result.&amp;nbsp; And if I have seen it, I remove the result, save the project and hope all references are killed during the save.&lt;/P&gt;&lt;P&gt;Good luck&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Feb 2017 05:50:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-do-you-close-raster-files-in-arcpy-created-by/m-p/406154#M31967</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2017-02-15T05:50:24Z</dc:date>
    </item>
    <item>
      <title>Re: How do you close raster files in Arcpy created by .save()?</title>
      <link>https://community.esri.com/t5/python-questions/how-do-you-close-raster-files-in-arcpy-created-by/m-p/406155#M31968</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Finicky is a good word. I used the 'del' statements as suggested and placed&amp;nbsp;a 'gc.collect()' at the end as suggested from some other threads to no avail. It turns out that I can modify the output file while the shell is still available while&amp;nbsp;the input files continue to be locked. Also, I ensured that ArcMap is not running. I'll keep my eyes peeled for a simple solution. Thanks for your time, Dan.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Feb 2017 06:49:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-do-you-close-raster-files-in-arcpy-created-by/m-p/406155#M31968</guid>
      <dc:creator>TylerJohnson7</dc:creator>
      <dc:date>2017-02-15T06:49:03Z</dc:date>
    </item>
    <item>
      <title>Re: How do you close raster files in Arcpy created by .save()?</title>
      <link>https://community.esri.com/t5/python-questions/how-do-you-close-raster-files-in-arcpy-created-by/m-p/406156#M31969</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Dan and Tyler,&lt;/P&gt;&lt;P&gt;Apologies for not getting back to you sooner, it's been a hectic few weeks starting this new job and trying to work out how arcpy and everything works.&amp;nbsp; I did try to make some example code to send you but this wasn't suffering the same problems and deleting the variables was cutting the connection with the files&amp;nbsp;and freeing the memory as hoped.&amp;nbsp; And now my code is working using this 'del'&amp;nbsp;method and I couldn't work out what had changed to share with you.&amp;nbsp; I can only think that you are right about it not working when Arcmap is open because it would have been open&amp;nbsp;when I first suffered this problem and asked the question&amp;nbsp;as I'd just installed it to get the code working in the first place, whereas I haven't opened it since and everything works now.&amp;nbsp; But since Tyler is having the same problem I first had then there is perhaps more to it and&amp;nbsp;something more complicated afoot.&lt;/P&gt;&lt;P&gt;Obviously it isn't ideal to delete the variables and even arcpy itself, especially when arcpy is so&amp;nbsp;finicky&amp;nbsp;about whether this will actually work;&amp;nbsp;so please let us know if you work out a better solution.&lt;/P&gt;&lt;P&gt;Cheers for the help!&lt;/P&gt;&lt;P&gt;Alex&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Feb 2017 10:20:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-do-you-close-raster-files-in-arcpy-created-by/m-p/406156#M31969</guid>
      <dc:creator>AlexWebb</dc:creator>
      <dc:date>2017-02-15T10:20:54Z</dc:date>
    </item>
  </channel>
</rss>

