I have to trigger some actions after the connection closes. This is the code
from sanic import response
from sanic.websocket import ConnectionClosed
@app.websocket('/tablefeed')
async def feed(request, ws):
try:
while True:
client_data = json.loads(await ws.recv())
client_code = client_data.get('id')
if client_code == 1: "do something"
except ConnectionClosed:
"do something else"
The "do something else" doesn't execute when client closes their connection. How can I get notified when the connection is lost?