<?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: Using multiprocessing in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/using-multiprocessing/m-p/1280140#M67456</link>
    <description>&lt;P&gt;Process.map returns an iterable of all individual results, so trying to print the whole res object could be getting wonky.&amp;nbsp; Maybe try:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;for res in p.map(my_body, listNumbers):
    arcpy.AddMessage("main " + str(res))
    print("main2 " + str(res))&lt;/LI-CODE&gt;&lt;P&gt;or this method of multiprocessing:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;with mp.Pool(processes=3) as pool:
    jobs = []
    for tple in listNumbers:
        jobs.append(pool.apply_async(my_body, (tple,) ))
    
    res = [j.get() for j in jobs]
    for r in res:
        arcpy.AddMessage('main ' + str(r))
        print('main ' + str(r))&lt;/LI-CODE&gt;&lt;P&gt;You could also return a dictionary of errors to help troubleshoot.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def my_body (parm):
    rdict = {'parm': parm, 'Error': None}
    try:
        arcpy.AddMessage("func " + str(parm))
        print("func2 " + str(parm))
       
    except Exception as ex:
        rdict['Error'] = ex
    return rdict


if __name__ == '__main__':
    listNumbers = [(1,1),(2,2),(3,3),(4,4)]

    p = multiprocessing.Pool(6)
    for res in p.map(my_body, listNumbers):
        arcpy.AddMessage("main " + str(res['parm']) + ' Error: ' + res['Error'])
        print("main2 " + str(res['parm']) + ' Error: ' + res['Error'])
    p.close()
    p.join()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 19 Apr 2023 12:58:54 GMT</pubDate>
    <dc:creator>Anonymous User</dc:creator>
    <dc:date>2023-04-19T12:58:54Z</dc:date>
    <item>
      <title>Using multiprocessing</title>
      <link>https://community.esri.com/t5/python-questions/using-multiprocessing/m-p/1280108#M67455</link>
      <description>&lt;P&gt;Hello all&lt;/P&gt;&lt;P&gt;I am trying to run multiprocessing python from Pro toolbox.&lt;/P&gt;&lt;P&gt;The simple code below works in IDLE with no problem (in PyScripter too).&lt;/P&gt;&lt;P&gt;It uses the print() and not AddMessage and the output comes with main2 since the child processes does not see the main window.&lt;/P&gt;&lt;P&gt;Trying to&amp;nbsp; run it in Pro toolbox gives unclear error message.&lt;/P&gt;&lt;P&gt;Trying to run it from notebook open many Pro's&amp;nbsp; (do not try this at home with a number bigger then 6 !!)&lt;/P&gt;&lt;P&gt;There are a few posts and blogs that say it should be possible&amp;nbsp;&lt;A href="https://www.esri.com/arcgis-blog/products/arcgis-desktop/analytics/python-multiprocessing-approaches-and-considerations/?rmedium=blogs_esri_com&amp;amp;rsource=/esri/arcgis/2011/08/29/multiprocessing/" target="_blank"&gt;https://www.esri.com/arcgis-blog/products/arcgis-desktop/analytics/python-multiprocessing-approaches-and-considerations/?rmedium=blogs_esri_com&amp;amp;rsource=/esri/arcgis/2011/08/29/multiprocessing/&lt;/A&gt;&amp;nbsp;but nothin new.&lt;/P&gt;&lt;P&gt;anybody is using this?&lt;/P&gt;&lt;P&gt;Each function (my_body) is complitly seperated from the others.&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import multiprocessing
import arcpy

def my_body (parm):
    arcpy.AddMessage("func " + str(parm))
    print("func2 " + str(parm))
    return(parm)


if __name__ == '__main__':
    listNumbers = [(1,1),(2,2),(3,3),(4,4)]

    p = multiprocessing.Pool(6)
    res = p.map(my_body, listNumbers)
    arcpy.AddMessage("main " + str(res))
    print("main2 " + str(res))
    p.close()
    p.join()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Apr 2023 11:11:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-multiprocessing/m-p/1280108#M67455</guid>
      <dc:creator>mody_buchbinder</dc:creator>
      <dc:date>2023-04-19T11:11:50Z</dc:date>
    </item>
    <item>
      <title>Re: Using multiprocessing</title>
      <link>https://community.esri.com/t5/python-questions/using-multiprocessing/m-p/1280140#M67456</link>
      <description>&lt;P&gt;Process.map returns an iterable of all individual results, so trying to print the whole res object could be getting wonky.&amp;nbsp; Maybe try:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;for res in p.map(my_body, listNumbers):
    arcpy.AddMessage("main " + str(res))
    print("main2 " + str(res))&lt;/LI-CODE&gt;&lt;P&gt;or this method of multiprocessing:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;with mp.Pool(processes=3) as pool:
    jobs = []
    for tple in listNumbers:
        jobs.append(pool.apply_async(my_body, (tple,) ))
    
    res = [j.get() for j in jobs]
    for r in res:
        arcpy.AddMessage('main ' + str(r))
        print('main ' + str(r))&lt;/LI-CODE&gt;&lt;P&gt;You could also return a dictionary of errors to help troubleshoot.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def my_body (parm):
    rdict = {'parm': parm, 'Error': None}
    try:
        arcpy.AddMessage("func " + str(parm))
        print("func2 " + str(parm))
       
    except Exception as ex:
        rdict['Error'] = ex
    return rdict


if __name__ == '__main__':
    listNumbers = [(1,1),(2,2),(3,3),(4,4)]

    p = multiprocessing.Pool(6)
    for res in p.map(my_body, listNumbers):
        arcpy.AddMessage("main " + str(res['parm']) + ' Error: ' + res['Error'])
        print("main2 " + str(res['parm']) + ' Error: ' + res['Error'])
    p.close()
    p.join()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Apr 2023 12:58:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-multiprocessing/m-p/1280140#M67456</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2023-04-19T12:58:54Z</dc:date>
    </item>
    <item>
      <title>Re: Using multiprocessing</title>
      <link>https://community.esri.com/t5/python-questions/using-multiprocessing/m-p/1280619#M67464</link>
      <description>&lt;P&gt;Hi Jeff&lt;/P&gt;&lt;P&gt;Thanks but you are missing the point.&lt;/P&gt;&lt;P&gt;In my real application I need each process to do something. At the most it should return True/false if it fail or not. I just use the AddMessage as arcpy command that will show that the process is running for my testing.&lt;/P&gt;&lt;P&gt;The main problem is that I cannot run this as a script from Toolbox in Pro.&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Thu, 20 Apr 2023 04:18:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-multiprocessing/m-p/1280619#M67464</guid>
      <dc:creator>mody_buchbinder</dc:creator>
      <dc:date>2023-04-20T04:18:14Z</dc:date>
    </item>
    <item>
      <title>Re: Using multiprocessing</title>
      <link>https://community.esri.com/t5/python-questions/using-multiprocessing/m-p/1320392#M68451</link>
      <description>&lt;P&gt;I am trying to do something almost identical to this and I'm getting a "cannot pickle my_body function" error. This is the same for an atbx and non-atbx toolbox script, although the latter also opens ~10 instances are arcgis pro (I assume due to the workers calling Pro.exe, not Python.exe).&lt;/P&gt;&lt;P&gt;Does anyone have a working solution for using multiprocessing in a Python toolbox? I need to use it for processing numpy arrays, not geoprocessors.&lt;/P&gt;</description>
      <pubDate>Sat, 19 Aug 2023 08:18:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-multiprocessing/m-p/1320392#M68451</guid>
      <dc:creator>LewisTrotter</dc:creator>
      <dc:date>2023-08-19T08:18:39Z</dc:date>
    </item>
  </channel>
</rss>

