I'm building a FastAPI application that has an endpoint to trigger a Dask computation. The API endpoint sends this call to the Dask scheduler and just returns the key of the Future
.
trigger
x = client.submit
(
function_name,
arg1,
arg2
)
return x.key
I have two other endpoints to retrieve the status and result of the task, which take the key
as input.
status
status = Future(key=key, client=client).status
return status
result
result = Future(key=key, client=client).result()
return result
Of course, this way, I lose the reference to the future after trigger
returns, in which case Dask doesn't compute this anymore. So even if the key is given to the client, we get the status as pending
forever.
What I'm doing now is storing references to the Future object as a python dictionary in the application, which works. But ideally, I would like my API application to be stateless. What would be store these Futures outside this application? Are there good caching libraries in Python that can store Python objects (with references)?
Try using Flask + Celery to handle the background Dask computation. Below are few links for reference:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.