title: Python multiprocessing, passing an object reference containig a semaphore
body: <p>I've a scenario like this:
  I've created an object of the class element containing a semaphore.</p>
  
  <pre><code>import multiprocessing as mpr
  
  class Element(object):
      def __init__(self):
          self.sem = mpr.Semaphore()
          self.xyz = 33
  
  def fun( ch ):
      a = ch.recv()
      print( a[0] )
      print( a[1].xyz )
      a[1].xyz = 99
      print( a[1].xyz )
  
  
  el = Element()
  
  ( pa , ch ) = mpr.Pipe()
  proc = mpr.Process(target=fun , args=( ch, ) )
  
  proc.start()
  pa.send( [ "Hallo" , el ])
  
  print( el.xyz )
  
  proc.join()
  </code></pre>
  
  <p>This code return this error:</p>
  
  <pre><code>  File "/usr/lib/python2.7/multiprocessing/forking.py", line 51, in assert_spawning
      ' through inheritance' % type(self).__name__
  RuntimeError: Semaphore objects should only be shared between processes through inheritance
  </code></pre>
  
  <p>But if I remove the semaphore from the declaration of <code>Element</code> the code works, but the value assigned to a[1].xyz will be lost.</p>
  
  <p>Now I need to synchronizes a big collection of object via semphore and multiprocessing.
   So there's some method for setting a semaphore in every  object and passing only the reference to the main object?</p>
  
  <pre><code>import multiprocessing as mpr
  
  class Element(object):
      def __init__(self):
          self.xyz = 33
  
  def fun( ch ):
      a = ch.recv()
      print( a[0] )
      print( a[1].xyz )
      a[1].xyz = 99
      print( a[1].xyz )
  
  
  el = Element()
  
  ( pa , ch ) = mpr.Pipe()
  proc = mpr.Process(target=fun , args=( ch, ) )
  
  proc.start()
  pa.send( [ "Hallo" , el ])
  
  print( el.xyz )
  
  proc.join()
  </code></pre>
  
  <p>The second version dot't produce any error, but the value assigned to <code>a[1].xyz = 99</code> will be lost in the main process.</p>