How to pass *args or **kwargs itself to the target function of threading.Target?
<p>A function accepts <code>*args</code> and <code>**kwargs</code>:</p>

<pre><code>def b(num, *args, **kwargs):
    print('num', num)
    print('args', args)
    print('kwargs', kwargs)
</code></pre>

<p>calling it as <code>b(5, *[1, 2], **{'a': 'b'})</code> produces the following output:</p>

<pre><code>num 5
args (1, 2)
kwargs {'a': 'b'}
</code></pre>

<p><code>threading.Thread(target=b, args=[5, [1, 2], {'a': 'b'}]).start()</code> gives:</p>

<pre><code>num 5
args ([1, 2], {'a': 'b'})
kwargs {}
</code></pre>

<p><code>threading.Thread(target=b, kwargs={'num': 5, '*args': [1, 2], '**kwargs': {'a': 'b'}}).start()</code> gives:</p>

<pre><code>num 5
args ()
kwargs {'**kwargs': {'a': 'b'}, '*args': [1, 2]}
</code></pre>

<p>What's the correct way to pass *args and **kwargs to this function?</p>

<pre><code>threading.Thread(target=b, args=[5, 1, 2], kwargs={'a': 'b'}).start()
</code></pre>

<p>gives the expected output. Another option is to use functools. The following code also passes arguments correctly:</p>

<pre><code>threading.Thread(target=functools.partial(b, 5, *[1, 2], **{'a': 'b'})).start()
</code></pre>

python python-multithreading