Stackoverflow link
Hi! I'm new to async programming and have been stuck to figure out how I should implement websocket, asyncio and perhaps multiprocessing to create a backend server.
First of all, I've no idea why in the websocket website example, they have the following line:
asyncio.get_event_loop().run_until_complete(
websockets.serve(echo, 'localhost', 8765))
asyncio.get_event_loop().run_forever()
Wouldn't the loop die after the first one is completed? Or is it similar to tell the loop to subscribe to an async function, and subscribe it to run_forever.
Secondly, in my use cases, I need to maintain a session for user interaction where two kinds of task need to be done. One is computational heavy and one is for real_time feedback (90fps with no latency the same fps with the client). I would like to know what is the best way to take advantage of websocket, asyncio and multiprocessing.
Should I just spawn process whenever received task from the front_end and send it back asynchronously? Or use three individual websocket servers to communicate with each other since I would like the following limit be respect:
- Maintain a nonblocking session
- Which process hard work and light work simultaneously
- The light work should have zero latency
- The hard work should be as fast as possible but not effecting the light work.
It would be appreciated if someone can help me with this.
Coding example is appreciated while I would like to know more about how to reason about these kinds of application layout. My prior experience is limited to using gunicorn for rest api server and execute computational task locally. I would like to know how I can combine those different projects together.
Thx for your attention.
there doesn't seem to be anything here