在使用python多线程module Threading时:

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

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

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()

 

相关文章:

  • 2021-07-06
  • 2021-08-17
  • 2021-08-05
  • 2022-12-23
  • 2021-08-31
  • 2021-11-05
  • 2021-11-07
  • 2022-12-23
猜你喜欢
  • 2021-09-25
  • 2021-07-28
  • 2022-01-05
  • 2022-12-23
  • 2022-12-23
  • 2021-11-22
  • 2021-07-21
相关资源
相似解决方案