I am building an application that will fetch and process N resources and then return a single aggregate result.
I would like to use concurrent.futures.ProcessPoolExecutor
to execute processing on the N resources in parallel, but found that this does not work because Sanic already is managing a process pool (something like that anyway).
So, I had another idea: Create an endpoint: /fetch_and_process_one_datum
I can call that in my main endpoint with:
request.app.asgi_client.get("/fetch_and_process_one_datum?params=...")
(but, inside a thread executor) so it will fetch them in parallel, and basically create N new requests. Then it will aggregate the results and return.
Is this an OK way to do this? Is there a better alternative?
it feels a little hacky making an endpoint that is only for internal purposes, and I wonder if there is a better way, but I could not find anything in the docs or issues.
Thanks!