title: multiprocess.apply_async How do I wrap *args and **kwargs?
body: <p>I'm trying to get <a href="http://docs.python.org/2/library/multiprocessing.html#multiprocessing.pool.multiprocessing.Pool.apply_async" rel="noreferrer"><code>multiprocess.apply_async</code></a> to take in both <code>*args</code> and <code>**kwargs</code>. The docs indicate that this might be possible with the calling sequence:</p>
  
  <pre><code>apply_async(func[, args[, kwds[, callback]]])
  </code></pre>
  
  <p>But I can not figure out how to get the calling syntax correct. With the minimal example:</p>
  
  <pre><code>from multiprocessing import Pool
  
  def f(x, *args, **kwargs):
      print x, args, kwargs
  
  args, kw = (), {}
  
  print "# Normal call"
  f(0, *args, **kw)
  
  print "# Multicall"
  P = Pool()
  sol = [P.apply_async(f, (x,), *args, **kw) for x in range(2)]
  P.close()
  P.join()
  
  for s in sol: s.get()
  </code></pre>
  
  <p>This works as expected giving the output </p>
  
  <pre><code># Normal call
  0 () {}
  # Multicall
  0 () {}
  1 () {}
  </code></pre>
  
  <p>When args is not an empty tuple, for example <code>args = (1,2,3)</code>, the single call works, but the multiprocessing solution gives:</p>
  
  <pre><code># Normal call
  0 (1, 2, 3) {}
  # Multicall
  Traceback (most recent call last):
    File "kw.py", line 16, in &lt;module&gt;
      sol = [P.apply_async(f, (x,), *args, **kw) for x in range(2)]
  TypeError: apply_async() takes at most 5 arguments (6 given)
  </code></pre>
  
  <p>With the kwargs argument I get, for example <code>kw = {'cat':'dog'}</code></p>
  
  <pre><code># Normal call
  0 () {'cat': 'dog'}
  # Multicall
  Traceback (most recent call last):
    File "kw.py", line 15, in &lt;module&gt;
      sol = [P.apply_async(f, (x,), *args, **kw) for x in range(2)]
  TypeError: apply_async() got an unexpected keyword argument 'cat'
  </code></pre>
  
  <p>How do I properly wrap <code>multiprocess.apply_async</code>?</p>