multithreading - Python: TypeError in Threading. function takes x positional argument but y were given -


i working python @ moment. have start-function, gets string message. want start threads every message.

the thread @ moment should print out message this:

def startsuggestworker(message):     print(message)  def start():     while true:         response = queue.receive_messages()         try:             message = response.pop()             start_keyword = message.body             t = threading.thread(target=startsuggestworker, args = (start_keyword))             t.start()             message.delete()         except indexerror:             print("messages empty")             sleep(150)  start() 

at moment typeerror , don't understand why. exception message one:

exception in thread thread-1: traceback (most recent call last):   file "/library/frameworks/python.framework/versions/3.5/lib/python3.5/threading.py", line 914, in _bootstrap_inner     self.run()   file "/library/frameworks/python.framework/versions/3.5/lib/python3.5/threading.py", line 862, in run     self._target(*self._args, **self._kwargs) typeerror: startsuggestworker() takes 1 positional argument y given 

*y = length of string

what doing wrong?

the args kwarg of threading.thread expects iterable, , each element in iterable being passed target function.

since providing string args:
t = threading.thread(target=startsuggestworker, args = (start_keyword))

each character being passed separate argument startsuggestworker.

instead, should provide args tuple:

t = threading.thread(target=startsuggestworker, args = (start_keyword,))


Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -