Pankaj Bhide
Pankaj Bhide

Reputation: 7

How to pass list and dictionary to thread create function

While creating the thread in the traditional way, I want to pass the list and dictionary objects; how to do that?

for example:

def expectslist(**kwargs):
    list=kwargs.values     -- not working

def expectsdict(**kwargs):
    dictobject=kwargs.values -- not working

def main():
     thread1 = Thread(target =expectslist,  (args=mylist)) # mylist is list of objects
     thread2 = Thread(target =expectsdict,  (args=mydict)) # mydict is dictionary of objects (key-objects pair)

Upvotes: 0

Views: 96

Answers (1)

balderman
balderman

Reputation: 23815

the value of args is a tuple that holds the thread func arguments.

Example:

def my_sum(x,y):
  return x + y

Thread(target = my_sum,args = (5,9))

Upvotes: 1

Related Questions