I'm trying to make a non-blocking code with python's asyncio. There are several threads about this topic but I still have not managed to adapt them to the code. This would be a minimal example based on this:
import asyncio
import websockets
async def ws_rec(websocket, path):
while True:
data = await websocket.recv()
print(data)
start_server = websockets.serve(ws_rec, 'localhost', 8765)
asyncio.get_event_loop().run_until_complete(start_server)
asyncio.get_event_loop().run_forever()
print("ok")
How could the code be adapted in order to print "ok"? Why do I even need asyncio for this?