在Python线程中传递多个参数

2024-09-28 21:30:59 发布

您现在位置:Python中文网/ 问答频道 /正文

下面的代码传递一个列表(varbinds),它工作正常。

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

现在我需要传递另一个变量-vString。

请帮助编写一个简单的代码。


Tags: 代码target列表argsthreadt1threadingvarbinds
1条回答
网友
1楼 · 发布于 2024-09-28 21:30:59

args参数是参数的元组。如果你不能通过很多论证,那又有什么意义呢?

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

但是您可以很快看到the documentation,下面是它的摘录:

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 {}.

相关问题 更多 >