#๐ Continue the post of websocket in quart
10 messages ยท Page 1 of 1 (latest)
@sharp sage
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
Closes after a period of inactivity, or when you send !close.
i have tried the TaskGroup and it said websocket is not defined
ExceptionGroup: unhandled errors in a TaskGroup (1 sub-exception)
+-+---------------- 1 ----------------
| Traceback (most recent call last):
| File "C:\Users\Asher\Desktop\Vocard_Dashboard\objects.py", line 42, in recv_loop
| message = await websocket.receive()
| ^^^^^^^^^
| NameError: name 'websocket' is not defined
@app.websocket("/ws_user")
@login_required
async def ws_user(user: User):
try:
# await user.connect(websocket)
async with asyncio.TaskGroup() as tg:
tg.create_task(user.recv_loop())
tg.create_task(user.send_loop())
except asyncio.CancelledError:
# await user.disconnect()
raise
class User:
...
async def recv_loop(self) -> None:
while True:
message = await websocket.receive()
print(message)
def send_nowait(self, message):
# Call this from Bot and vice versa
self._queue.put_nowait(message)
async def send_loop(self):
while True:
message = await self._queue.get()
await websocket.send(message)
you didnt define a variable called websocket
oh i thought it was a contextual variable
but after i defined the websocket the websocket will got replaced with a new websocket
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.