title: Is instance variable in Python 3.5 process-safe?
body: <p><strong>Testing Environment:</strong></p>
  
  <ul>
  <li>Python Version: 3.5.1</li>
  <li>OS Platform: Ubuntu 16.04</li>
  <li>IDE: PyCharm Community Edition 2016.3.2</li>
  </ul>
  
  <hr>
  
  <p>I write a simple program to test process-safe. I find that <code>subprocess2</code> won't run until <code>subprocess1</code> finished. It seems that the instance variable <code>self.count</code> is process-safe.How the process share this variable? Does they share <code>self</code> directly?</p>
  
  <p>Another question is when I use Queue, I have to use <code>multiprocessing.Manager</code> to guarantees process safety manually, or the program won't run as expected.(If you uncomment <code>self.queue = multiprocessing.Queue()</code>, this program won't run normally, but using <code>self.queue = multiprocessing.Manager().Queue()</code> is OK.)</p>
  
  <p>The last question is why the final result is <code>900</code>? I think it should be <code>102</code>.</p>
  
  <p>Sorry for asking so many questions, but I'm indeed curious about these things. Thanks a lot!</p>
  
  <p><strong>Code:</strong></p>
  
  <pre><code>import multiprocessing
  import time
  class Test:
      def __init__(self):
          self.pool = multiprocessing.Pool(1)
          self.count = 0
          #self.queue = multiprocessing.Queue()
          #self.queue = multiprocessing.Manager().Queue()
  
      def subprocess1(self):
          for i in range(3):
              print("Subprocess 1, count = %d" %self.count)
              self.count += 1
              time.sleep(1)
          print("Subprocess 1 Completed")
  
      def subprocess2(self):
          self.count = 100
          for i in range(3):
              print("Subprocess 2, count = %d" %self.count)
              self.count += 1
              time.sleep(1)
          print("Subprocess 2 Completed")
  
      def start(self):
          self.pool.apply_async(func=self.subprocess1)
          print("Subprocess 1 has been started")
          self.count = 900
          self.pool.apply_async(func=self.subprocess2)
          print("Subprocess 2 has been started")
          self.pool.close()
          self.pool.join()
  
      def __getstate__(self):
          self_dict = self.__dict__.copy()
          del self_dict['pool']
          return self_dict
  
      def __setstate__(self, state):
          self.__dict__.update(state)
  
  if __name__ == '__main__':
      test = Test()
      test.start()
      print("Final Result, count = %d" %test.count)
  </code></pre>
  
  <p><strong>Output:</strong></p>
  
  <pre><code>Subprocess 1 has been started
  Subprocess 2 has been started
  Subprocess 1, count = 0
  Subprocess 1, count = 1
  Subprocess 1, count = 2
  Subprocess 1 Completed
  Subprocess 2, count = 100
  Subprocess 2, count = 101
  Subprocess 2, count = 102
  Subprocess 2 Completed
  Final Result, count = 900
  </code></pre>