gpt4 book ai didi

python - 在 Python 线程中传递多个参数

转载 作者:行者123 更新时间:2023-11-28 22:32:50 24 4
gpt4 key购买 nike

以下代码传递了一个列表 (varbinds),并且工作正常。

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

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

请帮忙写一个简单的代码。

最佳答案

args 参数是一个元组,允许您将许多参数传递给目标。

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

这已记录在案 here :

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

关于python - 在 Python 线程中传递多个参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40581649/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com