title: Mysterious pickle error while profiling a multi-process Python script
body: <p>I"m using the <code>multiprocessing</code> module, and I'm using <code>UpdateMessage</code> objects (my own class), sent through <code>multiprocessing.Queue</code> objects, to communicate between processes. Here's the class:</p>
  
  <pre><code>class UpdateMessage:
      def __init__(self, arrayref, rowslice, colslice, newval):
          self.arrayref = arrayref
          self.rowslice = rowslice
          self.colslice = colslice
          self.newval = newval
      def do_update(self):
          if self.arrayref == 'uL':
              arr = uL
          elif self.arrayref == 'uR':
              arr = uR
          else:
              raise Exception('UpdateMessage.arrayref neither uL nor uR')
          arr[self.rowslice, self.colslice] = self.newval
  </code></pre>
  
  <p>When I run the script, it works perfectly fine. However, when I run it with either <code>cProfile</code> or <code>profile</code>, it gives the following error:</p>
  
  <pre><code>_pickle.PicklingError: Can't pickle &lt;class '__main__.UpdateMessage'&gt;: attribute lookup __main__.UpdateMessage failed
  </code></pre>
  
  <p>It seems to be trying to pickle the class, but I can't see why this is happening. My code doesn't do this, and it works just fine without it, so it's probably the <code>multiprocessing</code> module. But why would it need to pickle <code>UpdateMessage</code>, and how can I fix the error?</p>
  
  <p>EDIT: here's part of the code that's sending the <code>UpdateMessage</code> (multiple parts of the script do this, but all in the same way):</p>
  
  <pre><code>msg = UpdateMessage(uLref, refer[0] + marker[0] - 2,
                      slice(uL.shape[1]), ustar.copy())
  queue.put(msg)
  </code></pre>
  
  <p>The traceback isn't very helpful:</p>
  
  <pre><code>Traceback (most recent call last):
    File "/usr/lib/python3.2/multiprocessing/queues.py", line 272, in _feed
      send(obj)
  </code></pre>