<?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: does the in_memory workspace be mutually influenced   in every subprocess in multiprocess? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/does-the-in-memory-workspace-be-mutually/m-p/1033501#M60240</link>
    <description>&lt;P&gt;Processes within a pool don't share memory unless objects are passed as specific multiprocessing data types, e.g., multiprocessing.Array .&amp;nbsp; Since you are not doing that in your code (&lt;EM&gt;I am not even sure any ArcPy objects can be passed that way&lt;/EM&gt;), the in-memory workspace in each worker process is independent of the others.&lt;/P&gt;&lt;P&gt;An example:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from multiprocessing import Pool
import arcpy
import time

i = 0
def f(x):
    global i
    i += 1
    
    arcpy.CreateTable_management("in_memory", "xx{}".format(i))
    time.sleep(1)
    
    arcpy.env.workspace = "in_memory"
    return arcpy.ListTables()


if __name__ == '__main__':
    with Pool(4) as p:
        print(p.map(f, range(6)))&lt;/LI-CODE&gt;&lt;P&gt;Yields:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;[['xx1'], ['xx1'], ['xx1'], ['xx1'], ['xx1', 'xx2'], ['xx1', 'xx2']]
&amp;gt;&amp;gt;&amp;gt; &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As you can see, each of the four worker processes is able to create the same-named table in its in-memory workspace, and each arcpy.ListTables() only sees the tables in its own in-memory workspace.&lt;/P&gt;</description>
    <pubDate>Fri, 05 Mar 2021 17:58:25 GMT</pubDate>
    <dc:creator>JoshuaBixby</dc:creator>
    <dc:date>2021-03-05T17:58:25Z</dc:date>
    <item>
      <title>does the in_memory workspace be mutually influenced   in every subprocess in multiprocess?</title>
      <link>https://community.esri.com/t5/python-questions/does-the-in-memory-workspace-be-mutually/m-p/1033247#M60221</link>
      <description>&lt;P&gt;I have write a py script with multiprocess, like this:&lt;/P&gt;&lt;P&gt;import arcpy&lt;/P&gt;&lt;P&gt;from multiprocessing import Pool&lt;/P&gt;&lt;P&gt;def worker(fc):&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; arcpy.featureclasstofeatureclass(fc,r"in_memory","tempfc")&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; ## do something for tempfc&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; arcpy.delete_management("in_memory")&lt;/P&gt;&lt;P&gt;if __name__=="__main__":&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; p=Pool(3)&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; fcs=..... ## get some featureclasses&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; p.map(worker,fcs)&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; p.close()&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; p.join()&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to know if the created "tempfc" and deleted&amp;nbsp; in_memory workspace will be mutually influenced in&amp;nbsp; different subprocess?&lt;/P&gt;</description>
      <pubDate>Fri, 05 Mar 2021 03:07:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/does-the-in-memory-workspace-be-mutually/m-p/1033247#M60221</guid>
      <dc:creator>pyfans</dc:creator>
      <dc:date>2021-03-05T03:07:45Z</dc:date>
    </item>
    <item>
      <title>Re: does the in_memory workspace be mutually influenced   in every subprocess in multiprocess?</title>
      <link>https://community.esri.com/t5/python-questions/does-the-in-memory-workspace-be-mutually/m-p/1033501#M60240</link>
      <description>&lt;P&gt;Processes within a pool don't share memory unless objects are passed as specific multiprocessing data types, e.g., multiprocessing.Array .&amp;nbsp; Since you are not doing that in your code (&lt;EM&gt;I am not even sure any ArcPy objects can be passed that way&lt;/EM&gt;), the in-memory workspace in each worker process is independent of the others.&lt;/P&gt;&lt;P&gt;An example:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from multiprocessing import Pool
import arcpy
import time

i = 0
def f(x):
    global i
    i += 1
    
    arcpy.CreateTable_management("in_memory", "xx{}".format(i))
    time.sleep(1)
    
    arcpy.env.workspace = "in_memory"
    return arcpy.ListTables()


if __name__ == '__main__':
    with Pool(4) as p:
        print(p.map(f, range(6)))&lt;/LI-CODE&gt;&lt;P&gt;Yields:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;[['xx1'], ['xx1'], ['xx1'], ['xx1'], ['xx1', 'xx2'], ['xx1', 'xx2']]
&amp;gt;&amp;gt;&amp;gt; &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As you can see, each of the four worker processes is able to create the same-named table in its in-memory workspace, and each arcpy.ListTables() only sees the tables in its own in-memory workspace.&lt;/P&gt;</description>
      <pubDate>Fri, 05 Mar 2021 17:58:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/does-the-in-memory-workspace-be-mutually/m-p/1033501#M60240</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2021-03-05T17:58:25Z</dc:date>
    </item>
  </channel>
</rss>

