multithreading - Python how to initialize thread with unknown number of arguments? -


I'm having trouble using starred expressions with certain logic lists while trying to create threads.

Consider the following code:

  the_queue = queue () def do_something (arg1, arg2, queue): # some things ... result = arg1 + arg2 queue .put (results) Def init_thread (* arguments): t = thread (target = do_something, args = (argument, the_queue)) t.start () t.join () init_thread (3,6)   This throws an exception:  
  TypeError: do_something () takes exactly 3 arguments (2 given)   

In other words, "Logic" Tuplal is evaluated as a taple object (i.e. it has not been unpacked), and the_queue is the form of the second argument Switch to be considered.

The code should be able to call different methods with unknown numbers of arguments, but it is always a "Q" parameter at the end.

Is there any way to do this? In that case, how? And if not - what am I doing wrong?

Thank you.

Edit: I should call the "init_thread ()" method with the queue because one argument is not an option because I do not want the rest, my code should be "aware" of how the thread handler Works internally ...

You get a new taple .

  t = thread (target = do_something, args = arguments + (the_queue,))    

Comments