TypeError: recv_thread() argument after * must be an iterable, not socket

错误

TypeError: recv_thread() argument after * must be an iterable, not socket的问题。

原因

这个错误是由于在创建一个线程时,将socket对象作为args参数传递给了recv_thread函数,而args参数需要一个可迭代的对象,比如元组或列表。

解决办法

可以通过在socket对象后面加一个逗号,将其转换为一个元组,来解决这个问题。代码是这样的:

复制代码
def recv_thread(sock):
    while True:
        data = sock.recv(1024).decode()

thread = threading.Thread(target=recv_thread, args=(s))

可以改为:

复制代码
def recv_thread(sock):
    while True:
        data = sock.recv(1024).decode()
        
thread = threading.Thread(target=recv_thread, args=(s,))

这样就可以避免TypeError: recv_thread() argument after * must be an iterable, not socket的错误了。

(1) Python Threading module Error argument after * must be an iterable, not int. multithreading - Python Threading module Error argument after * must be an iterable, not int - Stack Overflow.

(2) TypeError: send() argument after * must be an iterable, not socket in .... SolvedTypeError: send() argument after * must be an iterable, not socket in Python.

(3) Python threading error - must be an iterable, not int. multithreading - Python threading error - must be an iterable, not int - Stack Overflow.

(4) python - TypeError: add() argument after * must be an iterable, not .... python - TypeError: add() argument after * must be an iterable, not Settings - Stack Overflow.

相关推荐
计算机编程指导师5 分钟前
【计算机毕设推荐】基于Hadoop+Spark的公共交通运营数据分析与可视化系统源码 毕业设计 选题推荐 毕设选题 数据分析 机器学习
大数据·hadoop·python·计算机·数据分析·spark·交通
Wx-bishekaifayuan7 分钟前
springboot汉中旅游服务平台41442-计算机课程设计、毕业设计
spring boot·后端·python·django·课程设计·express·旅游
WeiXin_DZbishe21 分钟前
基于springboot城市公交实时运营与调度系统-计算机毕设 附源码【课程设计】66173
java·vue.js·spring boot·后端·python·php·课程设计
泡茶喝茶写代码25 分钟前
A股量化数据工程:从 REST 接口到策略信号(第 18 篇):放量缩量异动扫描
java·python·股票数据api·股票数据api接口·股票api数据接口·股票量化数据api·股票量化数据接口
WeiXin_DZbishe42 分钟前
基于Springboot+AI的kuall音乐广场的设计与实现-计算机毕设 附源码【课程设计】12715
vue.js·人工智能·spring boot·后端·python·php·课程设计
wewowilling1 小时前
认识微服务
java·运维·微服务·springcloud
玖石书1 小时前
Ubuntu 24.04 UFW 全命令攻略:从入门到端口开放实战
linux·运维·ubuntu
imgsq2 小时前
电子学会考级 vs CCF-GESP:两套少儿编程考级怎么选
python·青少年编程
Smoothcloud润云3 小时前
PyTorch推理服务动态批处理实战:兼顾吞吐与延迟
人工智能·pytorch·python·深度学习·ai·gpu算力