我不知道这里的错误是什么我知道这很乱但是在客户端连接并发送消息后我得到了一个异常这里的错误IDException in thread Thread-1:Traceback (most recent call last): File "C:\Heights\PortableApps\PortablePython2.7.6.1\App\lib\threading.py", line 810, in __bootstrap_inner self.run() File "C:\Heights\PortableApps\PortablePython2.7.6.1\App\lib\threading.py", line 763, in run self.__target(*self.__args, **self.__kwargs) File "C:\Users\Gadi Tepper\PycharmProjects\Connection1\functions.py", line 12, in check_available_message user_uid = user.user_uidAttributeError: Message instance has no attribute 'user_uid'这是功能import timefrom message import *from user import *def check_available_message(messages, users): while True: for message in messages: for user in users: user_uid = user.user_uid dest_uid = message.receiver_uid if user_uid == dest_uid: print("got here") send_message(messages, message, user.user_socket)def send_message(messages, message, user_socket): print(message.sender_uid + " can send a message to: " + message.sender_uid) time.sleep(1) data = str((message.receiver_uid + "//" + message.sender_uid + "//" + message.data)).encode user_socket.send(data) messages.remove(message)这些是对象class User: def __init__(self, user_uid, user_socket): self.user_uid = user_uid self.user_socket = user_socketclass Message: def __init__(self, sender_uid, receiver_uid, data): self.sender_uid = sender_uid self.receiver_uid = receiver_uid self.data = data
2 回答
互换的青春
TA贡献1797条经验 获得超6个赞
你在向后传递你的论点。您像这样设置线程:
target=check_available_message, args=(users, messages))
但是您的方法需要消息作为第一个参数,用户作为第二个参数:
def check_available_message(messages, users):
繁星淼淼
TA贡献1775条经验 获得超11个赞
您的服务器中的参数顺序错误。在 functions.py 中,你正在接受check_available_message(messages, users)
,在服务器中你有另一个订单 -args=(users, messages)
添加回答
举报
0/150
提交
取消