Was fehlt mir hier? Der Standard -Thread -Executor funktioniert, aber in diesem Fall ist die Abgeordnete parallelistisch schneller (minimales E/O). Nützliche Informationen (keine Websockets):
Wie man sich in Fastapi multiprocessing macht.
Code: Select all
@app.websocket_route("/ws")
async def websocket_endpoint(websocket: WebSocket):
pool = ProcessPoolExecutor() #used instead of default/threadpool
loop = asyncio.get_event_loop()
queue = asyncio.Queue()
s = CICADA(clip_class, queue)
await websocket.accept()
while True:
data = await websocket.receive_json()
#should be non-blocking and terminate on "stop" message
loop.run_in_executor(pool, update_cicada(data, s, queue))
#update_cicada adds to queue thus updating client
result = await queue.get()
websocket.send_json(result) #so process can update client whithout terminating