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

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


Use the kwargs parameter:

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


you can also use lambda to pass args

threading.Thread(target=lambda: self._thread_function(arg1, arg2=arg2, arg3=arg3)).start()