title: How to store return value of function in multiprocessing process in python?
body: <p>I am writing a python program which executes functions in parallel manner. Here is code:</p>
  
  <pre><code>from multiprocessing import Process
  
  def sqr(args):
      results = []
      for i in args:
          results.append(i*i)
      return results
  
  def cube(args):
      results = []
      for i in args:
          results.append(i*i*i)
      return results
  
  def main():
      data = [1,2,3,4,5]
      p1 = Process(target=sqr, args=(data,))
      p1.start()
      p2 = Process(target=cube, args=(data,))
      p2.start()
      p1.join()
      p2.join()
  
  
  main()
  </code></pre>
  
  <p>I don't have idea how can I get return values of <code>sqr</code> and <code>cube</code> functions.</p>
  
  <p>I have tried this:</p>
  
  <pre><code>from multiprocessing import Process
  from queue import Queue
  
  def sqr(args, q):
      results = []
      for i in args:
          results.append(i*i)
      q.put(results)
  
  def cube(args, q):
      results = []
      for i in args:
          results.append(i*i*i)
      q.put(results)
  
  def main():
      q = Queue()
      data = [1,2,3,4,5]
      p1 = Process(target=sqr, args=(data, q))
      p1.start()
      p2 = Process(target=cube, args=(data, q))
      p2.start()
      p1.join()
      p2.join()
      print(q.get())
  
  main()
  </code></pre>
  
  <p>This program will suspend for infinite time. I don't understand what's going wrong here?
  can anybody help me, how can I store return result of function? Any help would be appreciated.</p>