消费者生产者陷入了多客户的困境

2024-10-03 11:18:26 发布

您现在位置:Python中文网/ 问答频道 /正文

我有个问题。我在这个聊天服务器上的生产者消费者被卡住了。它是这样做的:它让客户端轮流发送消息,当随机客户端(在我的计算机内部)发送消息时,所有客户端之前尝试发送的消息都被发送。我找不到问题,也许有人能发现

    def run(self):
    global condition
    global messages
    is_running = 1
    while is_running:

        print "waiting to receive from: " + self.usersock.getpname()
        inp = self.sock.recv(8192)

        condition.acquire()
        parts = inp.split(':-:321')
        if parts[0] == "4":
            while not noMessagesToSend(messages):
                condition.wait()    
            mes = message.message(str(datetime.datetime.now().time())[:8], self.usersock.id, parts[3],parts[4])
            if not mes.getgroup() in messages.keys():
                messages.update({mes.getgroup():[]})
            messages[mes.getgroup()].append(mes)
            condition.notifyAll()
            condition.release()
        else:
            print parts

Tags: self消息客户端isconditionglobalrunningparts