title: Python multiprocessing--global variables in separate processes sharing id?
body: <p>From <a href="https://stackoverflow.com/questions/11055303/python-multiprocessing-global-variable-updates-not-returned-to-parent?noredirect=1&amp;lq=1">this question</a> I learned that:</p>
  
  <blockquote>
    <p>When you use multiprocessing to open a second process, an entirely new
    instance of Python, with its own global state, is created. That global
    state is not shared, so changes made by child processes to global
    variables will be invisible to the parent process.</p>
  </blockquote>
  
  <p>To verify this behavior, I made a test script:</p>
  
  <pre><code>import time
  import multiprocessing as mp
  from multiprocessing import Pool
  x = [0]  # global
  def worker(c):
      if c == 1:  # wait for proc 2 to finish; is global x overwritten by now?
          time.sleep(2)
      print('enter: x =', x, 'with id', id(x), 'in proc', mp.current_process())
      x[0] = c
      print('exit: x =', x, 'with id', id(x), 'in proc', mp.current_process())
      return x[0]
  
  pool = Pool(processes=2)
  x_vals = pool.map(worker, [1, 2])
  print('parent: x =', x, 'with id', id(x), 'in proc', mp.current_process())
  print('final output', x_vals)
  </code></pre>
  
  <p>The output (on CPython) is something like</p>
  
  <pre><code>enter: x = [0] with id 140138406834504 in proc &lt;ForkProcess(ForkPoolWorker-2, started daemon)&gt;
  exit: x = [2] with id 140138406834504 in proc &lt;ForkProcess(ForkPoolWorker-2, started daemon)&gt;
  enter: x = [0] with id 140138406834504 in proc &lt;ForkProcess(ForkPoolWorker-1, started daemon)&gt;
  exit: x = [1] with id 140138406834504 in proc &lt;ForkProcess(ForkPoolWorker-1, started daemon)&gt;
  parent: x = [0] with id 140138406834504 in proc &lt;_MainProcess(MainProcess, started)&gt;
  final output [1, 2]
  </code></pre>
  
  <p>How should I explain the fact that the <code>id</code> of <code>x</code> is shared in all the processes, yet <code>x</code> takes different values? Isn't <a href="https://stackoverflow.com/a/15667328/4115369"><code>id</code> conceptually the memory address of a Python object</a>? 
  I guess this is possible if the memory space gets cloned in the child processes. Then is there something I can use to get the actual physical memory address of a Python object?</p>