title: How to share data between two processes?
body: <p>How can I share values from one process with another?
  Apparently I can do that through multithreading but not multiprocessing.
  Multithreading is slow for my program.</p>
  <p>I cannot show my exact code so I made this simple example.</p>
  <pre><code>from multiprocessing import Process
  from threading import Thread
  import time
  
  class exp:
      def __init__(self):
          self.var1 = 0
              
      def func1(self):
  
          self.var1 = 5
          print(self.var1)
  
      def func2(self):
  
          print(self.var1) 
  
  
  if __name__ == &quot;__main__&quot;:
  
      #multithreading
      obj1 = exp()
      t1 = Thread(target = obj1.func1)
      t2 = Thread(target = obj1.func2)
      print(&quot;multithreading&quot;)
      t1.start()
      time.sleep(1)
      t2.start()
  
      time.sleep(3)
  
  
      #multiprocessing
      obj = exp()
      p1 = Process(target = obj.func1)
      p2 = Process(target = obj.func2)
  
      print(&quot;multiprocessing&quot;)
      p1.start()
      time.sleep(2)
      p2.start()
  </code></pre>
  <p><strong>Expected output</strong>:</p>
  <pre class="lang-none prettyprint-override"><code>multithreading
  5
  5
  multiprocessing
  5
  5
  </code></pre>
  <p><strong>Actual output</strong>:</p>
  <pre class="lang-none prettyprint-override"><code>multithreading
  5
  5
  multiprocessing
  5
  0
  </code></pre>