<?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: Python multiprocessing not shutting down child processes in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/python-multiprocessing-not-shutting-down-child/m-p/72346#M5945</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hmmm rings a bell for a different situation try but I can't remember the details&lt;/P&gt;&lt;P&gt;results = main()&amp;nbsp; # to ensure that the results are returned from the main script&lt;/P&gt;&lt;P&gt;EDIT&lt;/P&gt;&lt;P&gt;a bit more difficult... see the programming guidelines for multiprocessing here&lt;/P&gt;&lt;P&gt;&lt;A href="https://docs.python.org/3.4/library/multiprocessing.html#programming-guidelines" title="https://docs.python.org/3.4/library/multiprocessing.html#programming-guidelines"&gt;17.2. multiprocessing — Process-based parallelism — Python 3.4.4 documentation&lt;/A&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 30 Mar 2016 15:47:03 GMT</pubDate>
    <dc:creator>DanPatterson_Retired</dc:creator>
    <dc:date>2016-03-30T15:47:03Z</dc:date>
    <item>
      <title>Python multiprocessing not shutting down child processes</title>
      <link>https://community.esri.com/t5/python-questions/python-multiprocessing-not-shutting-down-child/m-p/72345#M5944</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;I wrote a Python script where I use &lt;A href="https://docs.python.org/3.4/library/multiprocessing.html#multiprocessing.pool.Pool.map" rel="nofollow noopener noreferrer" target="_blank"&gt;multiprocessing.Pool.map&lt;/A&gt; to run a function on different parts of a large dataset in parallel (read only, results are stored in a separate directory for each process).&lt;/P&gt;&lt;P&gt;The python sub-processes produce the expected results but they never close down so I end up with many python.exe processes running forever (even after the "master" script has finished). Each of these processes consume around 100 MB of RAM and I think I will run out of memory when I run this script on a full set of input parameters. I've been running it with 6 CPU cores but I end up with many more python processes running.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How come they are not shutting down? Have you seen something like that before?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm using ArcGIS 10.3.1 with ArcGIS Pro 1.1 and Python 3.4 (64 bit) installed for stand alone scripts.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;While my real script is much more complicated, this is essentially what I am doing:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy
import multiprocessing


def worker_function(pars)
&amp;nbsp;&amp;nbsp;&amp;nbsp; """Function to be run in parallel"""
&amp;nbsp;&amp;nbsp;&amp;nbsp; wd = pars.get('wd')
&amp;nbsp;&amp;nbsp;&amp;nbsp; # ... do some work with spatial analyst ...
&amp;nbsp;&amp;nbsp;&amp;nbsp; return {"result": ["spam", "eggs"]}


&amp;nbsp;&amp;nbsp;&amp;nbsp; # parameter sets is a list of dictionaries of primite Python strings
def main():
&amp;nbsp;&amp;nbsp;&amp;nbsp; parameter_sets = [
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # ...
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "flow_direction_raster": '...',
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "weight_raster": '...',
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "output_raster": '...',
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "relative_to": '...',
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "extent": '...',
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "wd": '...'
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # ...
&amp;nbsp;&amp;nbsp;&amp;nbsp; ]
&amp;nbsp;&amp;nbsp;&amp;nbsp; pool = multiprocessing.Pool(6)
&amp;nbsp;&amp;nbsp;&amp;nbsp; results = pool.map(worker_function, parameter_sets)
&amp;nbsp;&amp;nbsp;&amp;nbsp; return results

if __name__ == "__main__":
&amp;nbsp;&amp;nbsp;&amp;nbsp; main()&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 22:48:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-multiprocessing-not-shutting-down-child/m-p/72345#M5944</guid>
      <dc:creator>FilipKrál</dc:creator>
      <dc:date>2021-12-10T22:48:11Z</dc:date>
    </item>
    <item>
      <title>Re: Python multiprocessing not shutting down child processes</title>
      <link>https://community.esri.com/t5/python-questions/python-multiprocessing-not-shutting-down-child/m-p/72346#M5945</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hmmm rings a bell for a different situation try but I can't remember the details&lt;/P&gt;&lt;P&gt;results = main()&amp;nbsp; # to ensure that the results are returned from the main script&lt;/P&gt;&lt;P&gt;EDIT&lt;/P&gt;&lt;P&gt;a bit more difficult... see the programming guidelines for multiprocessing here&lt;/P&gt;&lt;P&gt;&lt;A href="https://docs.python.org/3.4/library/multiprocessing.html#programming-guidelines" title="https://docs.python.org/3.4/library/multiprocessing.html#programming-guidelines"&gt;17.2. multiprocessing — Process-based parallelism — Python 3.4.4 documentation&lt;/A&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 30 Mar 2016 15:47:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-multiprocessing-not-shutting-down-child/m-p/72346#M5945</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2016-03-30T15:47:03Z</dc:date>
    </item>
    <item>
      <title>Re: Python multiprocessing not shutting down child processes</title>
      <link>https://community.esri.com/t5/python-questions/python-multiprocessing-not-shutting-down-child/m-p/72347#M5946</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;What about closing out the pool after the results are returned:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;SPAN class="n"&gt;results = pool.map(worker_function, parameter_sets)&lt;/SPAN&gt;
&lt;SPAN class="n"&gt;pool&lt;/SPAN&gt;&lt;SPAN class="o" style="color: #666666;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;close&lt;/SPAN&gt;&lt;SPAN class="p"&gt;()&lt;/SPAN&gt;
&lt;SPAN class="n"&gt;pool&lt;/SPAN&gt;&lt;SPAN class="o" style="color: #666666;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;join&lt;/SPAN&gt;&lt;SPAN class="p"&gt;()&lt;/SPAN&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 22:48:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-multiprocessing-not-shutting-down-child/m-p/72347#M5946</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2021-12-10T22:48:13Z</dc:date>
    </item>
    <item>
      <title>Re: Python multiprocessing not shutting down child processes</title>
      <link>https://community.esri.com/t5/python-questions/python-multiprocessing-not-shutting-down-child/m-p/72348#M5947</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;further down in that section there is an example of how to use map&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 30 Mar 2016 16:56:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-multiprocessing-not-shutting-down-child/m-p/72348#M5947</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2016-03-30T16:56:54Z</dc:date>
    </item>
    <item>
      <title>Re: Python multiprocessing not shutting down child processes</title>
      <link>https://community.esri.com/t5/python-questions/python-multiprocessing-not-shutting-down-child/m-p/72349#M5948</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you, calling pool.close() and pool.join() did the trick.&lt;/P&gt;&lt;P&gt;F.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 30 Mar 2016 20:59:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-multiprocessing-not-shutting-down-child/m-p/72349#M5948</guid>
      <dc:creator>FilipKrál</dc:creator>
      <dc:date>2016-03-30T20:59:30Z</dc:date>
    </item>
  </channel>
</rss>

