原文链接:http://www.juzicode.com/archives/2756
错误提示:
开启线程时提示TypeError: func() argument after * must be an iterable, not int
#juzicode.com/vx:桔子code
import threading
def func(para1):
print(para1)
if __name__ == '__main__':
para1 =11
t0 = threading.Thread(target=func, name='func-0',args=(para1))
t0.start()
Exception in thread func-0:
Traceback (most recent call last):
File "d:\python\python38\lib\threading.py", line 932, in _bootstrap_inner
self.run()
File "d:\python\python38\lib\threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
TypeError: func() argument after * must be an iterable, not int

可能原因:
1、使用threading.Thread()创建线程时,args参数传递的是一个元组,即使这个时候函数只有1个参数

博客围绕Python开启线程时出现的TypeError错误展开。错误提示为func()参数必须是可迭代对象而非整数,可能原因是使用threading.Thread()创建线程时,args参数传递未用元组。解决方法是改用元组传递参数,且单个参数时后面要加逗号。
最低0.47元/天 解锁文章
560





