获取 cerely 队列中的数据
时间: 2024-05-04 21:21:26 浏览: 11
要获取 celery 队列中的数据,可以使用以下代码:
```python
from celery import Celery
app = Celery('tasks', broker='pyamqp://guest@localhost//')
@app.task
def add(x, y):
return x + y
result = add.delay(4, 4)
print(result.get())
```
在这个例子中,我们定义了一个 Celery 应用程序并创建了一个任务。我们使用 `add.delay()` 发送一个任务到队列中,并使用 `result.get()` 获取任务的结果。需要注意的是,`get()` 方法会阻塞程序,直到任务完成并返回结果。如果任务还没有完成,`get()` 方法将等待直到任务完成。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![gz](https://img-home.csdnimg.cn/images/20210720083447.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![deb](https://img-home.csdnimg.cn/images/20210720083646.png)
![deb](https://img-home.csdnimg.cn/images/20210720083646.png)