TypeError in Threading. function takes 1 positional argument but 100 were given

时间:2021-12-31 23:19:59

Python Threading问题:TypeError in Threading. function takes 1 positional argument but 100 were given

在使用python多线程module Threading时

import threading
t = threading.Thread(target=getTemperature, args = (id1))
t.start()

运行时报如上的错误,参考*,如下解释

The args kwarg of threading.Thread expects an iterable, and each element in that iterable is being passed to the target function.

Since you are providing a string for args:
t = threading.Thread(target=startSuggestworker, args = (start_keyword))
each character is being passed as a separate argument to startSuggestworker.
Instead, you should provide args a tuple:
t = threading.Thread(target=startSuggestworker, args = (start_keyword,))
也就是args传递的参数类型不对,即使一个参数也要时元组的形式给出

import threading
...
t = threading.Thread(target=getTemperature, args = (id1,))
t.start()
...

参考:
https://*.com/questions/37116721/python-typeerror-in-threading-function-takes-x-positional-argument-but-y-were