I've trying to make a queueing system but its not working. The queueing logic im going with is that: Lets say have we have dictionary "queue" which contains the queues. When the dict is empty, we are gonna create a code, add our name to to it, and add all that to the dictionary as an item, and save allat via sessions, AND MOST IMPORTANTLY: Check if the number of members become 2, if in that case, we redirect to /chat. When the dict is not empty, the code we're gonna use is the key of the 1st item in the dict, and save it via sessions, and redirect to /chat
The problem im facing is that the creator of the item in the dictionary, i.e when u click on it when list is empty, THEY DONT REDIRECT. But if ur not the creator of the queue item, instead u click on it when there is already an item (u join, basically), u redirect.
I think the problem lies in the checking of the number of members when an item is created when there are no members, which i wrote under an if statement. Under that if statement is the checking, which i wrote in a While Loop.
CODE:
#on submitting / on post request if len(queue) == 0: code = "".join(random.choices(ascii_uppercase, k=4)) queue
Код: Выделить всё
= {"members" : [name]} session["name"] = name session["favColor"] = favColor session["code"] = code while len(queue[code]["members"]) == 1: return render_template("waiting.html") else: return redirect(url_for("chat")) else: code = next(iter(queue)) queue[code]["members"].append(name) session["name"] = name session["favColor"] = favColor session["code"] = code if len(queue[code]["members"]) == 2: return redirect(url_for("chat")) [b]And I just mentioned[/b], the coder under the else statement is working fine "i think", its just the code under the if statement.
[b]HELP MY LIFE DEPENDS ON WETHER I MAKE THIS[/b]
Источник: [url]https://stackoverflow.com/questions/78092542/queueing-in-python-flask-for-an-omegle-clone[/url]