Manmathan Manmathan - 5 months ago 36
Python Question

Passing multiple arguments in Python thread

The following code passes a list (varbinds) and it works fine.

t1 = threading.Thread(target = Main2_TrapToTxtDb, args = (varBinds,))

Now I need to pass another variable - vString along with this.

Please help with a simple code.


The args parameter is a tuple of arguments. What's its point, if you cannot pass it many arguments?

t1 = threading.Thread(target=Main2_TrapToTxtDb, args=(varBinds, otherVariable))

But you could have seen quickly with the documentation, which the following is an extract of:

class threading.Thread(group=None, target=None, name=None, args=(), kwargs={})

This constructor should always be called with keyword arguments. Arguments are:

group should be None; reserved for future extension when a ThreadGroup class is implemented.

target is the callable object to be invoked by the run() method. Defaults to None, meaning nothing is called.

name is the thread name. By default, a unique name is constructed of the form “Thread-N” where N is a small decimal number.

args is the argument tuple for the target invocation. Defaults to ().

kwargs is a dictionary of keyword arguments for the target invocation. Defaults to {}.