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 .... [Solved]TypeError: 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.

相关推荐
WL_Aurora6 小时前
Python 算法基础篇之集合
python·算法
大明者省6 小时前
宝塔开了端口,Ubuntu 还得开相应端口才能打通
服务器·数据库·ubuntu
syagain_zsx6 小时前
Linux指令初识(实用篇)
linux·运维·服务器
OYangxf6 小时前
Git Commit Message
运维·git
头歌实践平台6 小时前
招聘大数据可视化
大数据·python
Alter12306 小时前
从“力大砖飞”到“拟态共生”,新华三定义AI基础设施的系统级进化
大数据·运维·人工智能
王木风6 小时前
终端里的编程副驾:DeepSeek-TUI-项目深度拆解,实测与原理分析
linux·运维·人工智能·rust·node.js
槑槑紫6 小时前
windows系统装轻量版linux开发
linux·运维·服务器
byte轻骑兵7 小时前
【HID】规范精讲[14]: 蓝牙HID流量规格配置实战——鼠标、键盘与手柄的QoS优化指南
服务器·计算机外设·人机交互·键盘·hid
齐潇宇7 小时前
k8s-Helm管理器
linux·运维·云原生·容器·kubernetes