I am trying to do the same thing as in this question: Run Class methods in threads (python), but the class method I want to invoke in a separate thread takes an extra argument, apart from self. A.Rodas's solution does not work: if I try Thread(target=self.class_method, args=(self, arg2)).start(), it says I have 3 arguments instead of 2, while if try args=(arg2), it is breaking my arg2 string into constituent elements and saying 334234 arguments! Any ideas? Thanks
Asked
Active
Viewed 859 times
0
-
Found the solution! Turns out it wasn't the class method that was causing the error, but the fact that I was sending a tuple of one arg. So I needed to sent args=(arg2,). Note the comma! Got the solution from here: https://stackoverflow.com/questions/37116721/python-typeerror-in-threading-function-takes-x-positional-argument-but-y-were – cbasavaraj Nov 13 '18 at 21:32
2 Answers
0
It is hard to tell from the format of your question, but I think the issue is that you shouldn't be including self
in the args
tuple.
i.e.
threading.Thread(target=self.class_method, args=(arg2)).start()

Ian MacDonald
- 13,472
- 2
- 30
- 51
0
You should do it like this:
threading.Thread(target=self.class_method, args=(arg2,)).start()

António Almeida
- 9,620
- 8
- 59
- 66

王国春
- 16