<?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 Out of memory error in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/out-of-memory-error/m-p/649565#M50550</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P style="color: #000000; font-family: Arial;"&gt;Hi there, &lt;/P&gt;&lt;P style="color: #000000; font-family: Arial;"&gt;&lt;/P&gt;&lt;P style="color: #000000; font-family: Arial;"&gt;I posted my problem few days before, but I think it may not be the problem of multiprocess, because when I use uni-process, I got the same error. I described my question more detail, hope someone could help with it. &lt;/P&gt;&lt;P style="color: #000000; font-family: Arial;"&gt;&lt;/P&gt;&lt;P style="color: #000000; font-family: Arial;"&gt;So I was going to use the clip function in arcpy. And the following is my code:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy, os, gc
from arcpy import env

env.workspace = r"F:/GCM_CMIP5/FGOALS-g2(LASG-CESS)/mrro/ShpFile/test/"
shpfilepath="F:/GCM_CMIP5/FGOALS-g2(LASG-CESS)/mrro/ShpFile/test/"

def data_clip():
&amp;nbsp;&amp;nbsp;&amp;nbsp; for f in os.listdir(shpfilepath):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if f[(f.find('.')+1):]=='shp':
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; in_features=f
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; clip_features = "D:/Research/boundry.shp"
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; out_feature_class = "F:/GCM_CMIP5/FGOALS-g2(LASG-CESS)/mrro/test/"+f[:f.find('.')]+"_china"+".shp"
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; xy_tolerance = ""
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Clip_analysis(in_features, clip_features, out_feature_class, xy_tolerance)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #del in_features, clip_features, out_feature_class, xy_tolerance
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #gc.collect()
&amp;nbsp;&amp;nbsp;&amp;nbsp; print('Clip finish!')
data_clip()

&lt;/PRE&gt;&lt;P style="color: #000000; font-family: Arial;"&gt;&lt;/P&gt;&lt;P style="color: #000000; font-family: Arial;"&gt;I was using the boundry shp file to clip the original shp file. I have lots of original shp file to clip, like maybe about 10,000 shp files (maybe more later). This code worked well at first, but the problem is it would show an out of memory error after maybe about 1,000 files were cliped. And I attached the details of the error. My laptop has 16G memory, but when I got the error, there still has about 10G memory I could use. I could separate these files into several file folders, and it could work well. However, in the future, I may need to deal with much more files, and the manual separation is not the way. Do you have any idea about how to solve it? Thanks a lot!&lt;/P&gt;&lt;P style="color: #000000; font-family: Arial;"&gt;&lt;/P&gt;&lt;P style="color: #000000; font-family: Arial;"&gt;And hope you all have a good day!&lt;/P&gt;&lt;P style="color: #000000; font-family: Arial;"&gt;&lt;/P&gt;&lt;P style="color: #000000; font-family: Arial;"&gt;Best,&lt;/P&gt;&lt;P style="color: #000000; font-family: Arial;"&gt;Hua&lt;/P&gt;&lt;P style="color: #000000; font-family: Arial;"&gt;&lt;IMG class="jive-image" data-image="1" src="http://uswebmail.mail.163.com/js6/s?func=mbox:getComposeData&amp;amp;sid=CAHFhvddNsXayAqSSDddoSXMqqCIVfHv&amp;amp;composeId=c:1453307362491&amp;amp;attachId=1&amp;amp;rnd=0.23753087711520493" /&gt;​&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 12 Dec 2021 03:32:56 GMT</pubDate>
    <dc:creator>HuaShang</dc:creator>
    <dc:date>2021-12-12T03:32:56Z</dc:date>
    <item>
      <title>Out of memory error</title>
      <link>https://community.esri.com/t5/python-questions/out-of-memory-error/m-p/649565#M50550</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P style="color: #000000; font-family: Arial;"&gt;Hi there, &lt;/P&gt;&lt;P style="color: #000000; font-family: Arial;"&gt;&lt;/P&gt;&lt;P style="color: #000000; font-family: Arial;"&gt;I posted my problem few days before, but I think it may not be the problem of multiprocess, because when I use uni-process, I got the same error. I described my question more detail, hope someone could help with it. &lt;/P&gt;&lt;P style="color: #000000; font-family: Arial;"&gt;&lt;/P&gt;&lt;P style="color: #000000; font-family: Arial;"&gt;So I was going to use the clip function in arcpy. And the following is my code:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy, os, gc
from arcpy import env

env.workspace = r"F:/GCM_CMIP5/FGOALS-g2(LASG-CESS)/mrro/ShpFile/test/"
shpfilepath="F:/GCM_CMIP5/FGOALS-g2(LASG-CESS)/mrro/ShpFile/test/"

def data_clip():
&amp;nbsp;&amp;nbsp;&amp;nbsp; for f in os.listdir(shpfilepath):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if f[(f.find('.')+1):]=='shp':
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; in_features=f
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; clip_features = "D:/Research/boundry.shp"
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; out_feature_class = "F:/GCM_CMIP5/FGOALS-g2(LASG-CESS)/mrro/test/"+f[:f.find('.')]+"_china"+".shp"
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; xy_tolerance = ""
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Clip_analysis(in_features, clip_features, out_feature_class, xy_tolerance)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #del in_features, clip_features, out_feature_class, xy_tolerance
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #gc.collect()
&amp;nbsp;&amp;nbsp;&amp;nbsp; print('Clip finish!')
data_clip()

&lt;/PRE&gt;&lt;P style="color: #000000; font-family: Arial;"&gt;&lt;/P&gt;&lt;P style="color: #000000; font-family: Arial;"&gt;I was using the boundry shp file to clip the original shp file. I have lots of original shp file to clip, like maybe about 10,000 shp files (maybe more later). This code worked well at first, but the problem is it would show an out of memory error after maybe about 1,000 files were cliped. And I attached the details of the error. My laptop has 16G memory, but when I got the error, there still has about 10G memory I could use. I could separate these files into several file folders, and it could work well. However, in the future, I may need to deal with much more files, and the manual separation is not the way. Do you have any idea about how to solve it? Thanks a lot!&lt;/P&gt;&lt;P style="color: #000000; font-family: Arial;"&gt;&lt;/P&gt;&lt;P style="color: #000000; font-family: Arial;"&gt;And hope you all have a good day!&lt;/P&gt;&lt;P style="color: #000000; font-family: Arial;"&gt;&lt;/P&gt;&lt;P style="color: #000000; font-family: Arial;"&gt;Best,&lt;/P&gt;&lt;P style="color: #000000; font-family: Arial;"&gt;Hua&lt;/P&gt;&lt;P style="color: #000000; font-family: Arial;"&gt;&lt;IMG class="jive-image" data-image="1" src="http://uswebmail.mail.163.com/js6/s?func=mbox:getComposeData&amp;amp;sid=CAHFhvddNsXayAqSSDddoSXMqqCIVfHv&amp;amp;composeId=c:1453307362491&amp;amp;attachId=1&amp;amp;rnd=0.23753087711520493" /&gt;​&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 03:32:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/out-of-memory-error/m-p/649565#M50550</guid>
      <dc:creator>HuaShang</dc:creator>
      <dc:date>2021-12-12T03:32:56Z</dc:date>
    </item>
    <item>
      <title>Re: Out of memory error</title>
      <link>https://community.esri.com/t5/python-questions/out-of-memory-error/m-p/649566#M50551</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Did you notice a difference when you deleted your variables and that is why you commented out the del line? Have you tried outputting your clipped files to another folder that does not have any "()" or "-"?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is there any reason you do not use &lt;SPAN style="color: #000000; font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px; background-color: #f6f6f6;"&gt;out_feature_class = &lt;/SPAN&gt;&lt;SPAN class="string" style="font-size: 12px; font-family: Consolas, 'Courier New', Courier, mono, serif; color: blue; background-color: #f6f6f6;"&gt;env.workspace &lt;/SPAN&gt;&lt;SPAN style="font-size: 12px; font-family: Consolas, 'Courier New', Courier, mono, serif; color: #000000; background-color: #f6f6f6;"&gt;+f[:f.find(&lt;/SPAN&gt;&lt;SPAN class="string" style="font-size: 12px; font-family: Consolas, 'Courier New', Courier, mono, serif; color: blue; background-color: #f6f6f6;"&gt;'.'&lt;/SPAN&gt;&lt;SPAN style="font-size: 12px; font-family: Consolas, 'Courier New', Courier, mono, serif; color: #000000; background-color: #f6f6f6;"&gt;)]+&lt;/SPAN&gt;&lt;SPAN class="string" style="font-size: 12px; font-family: Consolas, 'Courier New', Courier, mono, serif; color: blue; background-color: #f6f6f6;"&gt;"_china"&lt;/SPAN&gt;&lt;SPAN style="font-size: 12px; font-family: Consolas, 'Courier New', Courier, mono, serif; color: #000000; background-color: #f6f6f6;"&gt;+&lt;/SPAN&gt;&lt;SPAN class="string" style="font-size: 12px; font-family: Consolas, 'Courier New', Courier, mono, serif; color: blue; background-color: #f6f6f6;"&gt;".shp"&lt;/SPAN&gt;&lt;SPAN style="font-size: 12px; font-family: Consolas, 'Courier New', Courier, mono, serif; color: #000000; background-color: #f6f6f6;"&gt;&amp;nbsp; instead of typing the full path out again?&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 20 Jan 2016 19:14:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/out-of-memory-error/m-p/649566#M50551</guid>
      <dc:creator>LukeSturtevant</dc:creator>
      <dc:date>2016-01-20T19:14:25Z</dc:date>
    </item>
    <item>
      <title>Re: Out of memory error</title>
      <link>https://community.esri.com/t5/python-questions/out-of-memory-error/m-p/649567#M50552</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;also, just a nitpick&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;gt;&amp;gt;&amp;gt; if f[-4:] == ".shp":
...&amp;nbsp; in_features= f
...
&amp;gt;&amp;gt;&amp;gt; in_features
'c:\\somepath\\that\\contains\\a\\shapefile.shp'
&amp;gt;&amp;gt;&amp;gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 03:32:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/out-of-memory-error/m-p/649567#M50552</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2021-12-12T03:32:59Z</dc:date>
    </item>
  </channel>
</rss>

