title: Can't pickle instance method using Pool.map(), but I have no instance method
body: <p>I'm trying to use the <code>multiprocessing.Pool</code> object to run some database queries in parallel. I'm using MySQLdb.</p>
  
  <p>I have some module-level functions where I define queries to run, like this:</p>
  
  <pre><code>def check_foo(cursor, table):
      query = "(some query)"
      cursor.execute(query)
      results = cursor.fetchall()
      return len(results) == 0
  </code></pre>
  
  <p>These functions are collected when the program is run, like this:</p>
  
  <pre><code>if __name__ == '__main__':
      check_functions = [v for k, v in globals().items()
                               if k.startswith('check_') and callable(v)]
  </code></pre>
  
  <p>I also have a module-level function that runs a particular check function on a list of tables:</p>
  
  <pre><code>def run_check_on_all((tables, cursor, f)):
      return [f(cursor, table) for table in tables]
  </code></pre>
  
  <p>I want to have one worker process for each check function that will call <code>run_check_on_all</code> for that function. Here's my attempt to do that:</p>
  
  <pre><code>if __name__ == '__main__':
      ...
  
      pool = multiprocessing.Pool(len(check_functions))
      cursors = [conn.cursor() for i in range(len(check_functions))]
  
      print "Running {0} check(s)...".format(len(check_functions))
      table_lists = [table_list] * len(check_functions)
      all_results = pool.map(run_check_on_all, zip(table_lists, cursors, check_functions))
  </code></pre>
  
  <p>When I attempt to run this, I get the following error:</p>
  
  <pre><code>Exception in thread Thread-1:
  Traceback (most recent call last):
    File "/usr/local/Python2.6/lib/python2.6/threading.py", line 532, in __bootstrap_inner
      self.run()
    File "/usr/local/Python2.6/lib/python2.6/threading.py", line 484, in run
      self.__target(*self.__args, **self.__kwargs)
    File "/usr/local/Python2.6/lib/python2.6/multiprocessing/pool.py", line 225, in _handle_tasks
      put(task)
  PicklingError: Can't pickle &lt;type 'instancemethod'&gt;: attribute lookup __builtin__.instancemethod failed
  </code></pre>
  
  <p>As you can (hopefully) see, nothing involved in the call to <code>pool.map</code> is an instance method. <code>run_check_on_all</code> and each of the <code>check_functions</code> are module-level functions. <code>table_lists</code> is a list of lists of strings. <code>cursors</code> is a list of MySQLdb cursor objects.</p>
  
  <p>I thought maybe it had to do with calling the cursor objects' instance methods in the check functions, but I replaced them with dummy functions like this</p>
  
  <pre><code>def check_foo(cursor, table):
      print "hello"
  </code></pre>
  
  <p>and still no luck.</p>
  
  <p>Where is the instance method that the error is referring to?</p>