首页 > 编程语言 > 详细

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

时间:2019-04-26 14:49:16      阅读:222      评论:0      收藏:0      [点我收藏+]

在使用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()

 

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

原文:https://www.cnblogs.com/yyxianren/p/10774113.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!