title: How to recover the return value of a function passed to multiprocessing.Process?
body: <p>I have looked at this question to get started and it works just fine <a href="https://stackoverflow.com/questions/10415028/how-can-i-recover-the-return-value-of-a-function-passed-to-multiprocessing-proce">How can I recover the return value of a function passed to multiprocessing.Process?</a></p>
  <p>But in my case I would like to write a small tool, that would connect to many computers and gather some statistics, each stat would be gathered within a Process to make it snappy. But as soon as I try to wrap up the multiprocessing command in a class for a machine then it fails.</p>
  <p>Here is my code</p>
  <pre><code>import multiprocessing 
  import pprint
  
  
  def run_task(command):
      p = subprocess.Popen(command, stdout = subprocess.PIPE, universal_newlines = True, shell = False)
      result = p.communicate()[0]
      return result
  
  
  MACHINE_NAME = &quot;cptr_name&quot;
  A_STAT = &quot;some_stats_A&quot;
  B_STAT = &quot;some_stats_B&quot;
  
  class MachineStatsGatherer():
      def __init__(self, machineName):
          self.machineName = machineName
          manager = multiprocessing.Manager() 
          self.localStats = manager.dict() # creating a shared ressource for the sub processes to use
          self.localStats[MACHINE_NAME] = machineName
  
      def gatherStats(self):
          self.runInParallel(
              self.GatherSomeStatsA,
              self.GatherSomeStatsB,
              )
          self.printStats()
  
      def printStats(self):
          pprint.pprint(self.localStats)
  
      def runInParallel(self, *fns):
          processes = []
          for fn in fns:
              process = multiprocessing.Process(target=fn, args=(self.localStats))
              processes.append(process)
              process.start()
          for process in processes:
              process.join()
  
      def GatherSomeStatsA(self, returnStats):
          # do some remote command, simplified here for the sake of debugging
          result = &quot;Windows&quot;
          returnStats[A_STAT] = result.find(&quot;Windows&quot;) != -1
   
      def GatherSomeStatsB(self, returnStats):
          # do some remote command, simplified here for the sake of debugging
          result = &quot;Windows&quot;
          returnStats[B_STAT] = result.find(&quot;Windows&quot;) != -1
   
  
  def main():
      machine = MachineStatsGatherer(&quot;SOMEMACHINENAME&quot;)
      machine.gatherStats()
      return
  
  if __name__ == '__main__':
      main()
  </code></pre>
  <p>And here is the error message</p>
  <pre><code>Traceback (most recent call last):
    File &quot;C:\Users\mesirard\AppData\Local\Programs\Python\Python37\lib\multiprocessing\process.py&quot;, line 297, in _bootstrap
      self.run()
    File &quot;C:\Users\mesirard\AppData\Local\Programs\Python\Python37\lib\multiprocessing\process.py&quot;, line 99, in run
      self._target(*self._args, **self._kwargs)
    File &quot;d:\workdir\trunks6\Tools\VTKAppTester\Utils\NXMachineMonitorShared.py&quot;, line 45, in GatherSomeStatsA
      returnStats[A_STAT] = result.find(&quot;Windows&quot;) != -1
  TypeError: 'str' object does not support item assignment
  Process Process-3:
  Traceback (most recent call last):
    File &quot;C:\Users\mesirard\AppData\Local\Programs\Python\Python37\lib\multiprocessing\process.py&quot;, line 297, in _bootstrap
      self.run()
    File &quot;C:\Users\mesirard\AppData\Local\Programs\Python\Python37\lib\multiprocessing\process.py&quot;, line 99, in run
      self._target(*self._args, **self._kwargs)
    File &quot;d:\workdir\trunks6\Tools\VTKAppTester\Utils\NXMachineMonitorShared.py&quot;, line 50, in GatherSomeStatsB
      returnStats[B_STAT] = result.find(&quot;Windows&quot;) != -1
  TypeError: 'str' object does not support item assignment
  </code></pre>