简体   繁体   English

在 Flask/FastAPI 应用程序中存储对 Dask Futures 的引用

[英]Store references to Dask Futures in a Flask/FastAPI Application

I'm building a FastAPI application that has an endpoint to trigger a Dask computation.我正在构建一个 FastAPI 应用程序,它有一个端点来触发 Dask 计算。 The API endpoint sends this call to the Dask scheduler and just returns the key of the Future . API 端点将此调用发送到 Dask 调度程序并仅返回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.我还有另外两个端点来检索任务的状态和结果,它们将key作为输入。

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.当然,这样一来,我在trigger返回后失去了对未来的引用,在这种情况下,Dask 不再计算它了。 So even if the key is given to the client, we get the status as pending forever.因此,即使将密钥提供给客户端,我们也会永远处于pending状态。

What I'm doing now is storing references to the Future object as a python dictionary in the application, which works.我现在正在做的是将 Future object 的引用存储为应用程序中的 python 字典,它可以工作。 But ideally, I would like my API application to be stateless.但理想情况下,我希望我的 API 应用程序是无状态的。 What would be store these Futures outside this application?什么会在这个应用程序之外存储这些期货? Are there good caching libraries in Python that can store Python objects (with references)? Python 中是否有很好的缓存库可以存储 Python 对象(带有引用)?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM