How to pass a variable by name to a Thread in Python?

前端 未结 1 1254
暗喜
暗喜 2021-01-31 16:43

Say that I have a function that looks like:

def _thread_function(arg1, arg2=None, arg3=None):
    #Random code

Now I want to create a thread us

1条回答
  •  清歌不尽
    2021-01-31 17:37

    Use the kwargs parameter:

    threading.Thread(target=self._thread_function, args=(arg1,),
                     kwargs={'arg2':arg2}, name='thread_function').start()
    

    0 讨论(0)
提交回复
热议问题