【问题标题】:Async callbacks on firestore on_snapshot using python使用python对firestore on_snapshot进行异步回调
【发布时间】:2020-05-14 01:13:53
【问题描述】:

我有一个应用程序使用 google-cloud-firestore 监听来自 Firestore 集合的更新。对于每次更新,我都需要将一些数据上传到需要时间的 FTP 服务器。同时接收大量数据会引入不可接受的延迟,我认为答案是异步回调(即在继续之前不要等待我的回调结束),但这是可能的。

想象一下这样的脚本

from google.cloud.firestore import Client
import time


def callback(col_snapshot, changes, read_time):
    print("Received updates")

    # mock FTP upload
    time.sleep(1)
    print("Finished handling the updates")

Client().collection('news').on_snapshot(callback)

while True:
    pass

如何修改该代码,使其不会对每个回调进行排队。

更新

我在google-cloud-firestore创建了一个功能请求

【问题讨论】:

    标签: python google-cloud-firestore ftp python-asyncio


    【解决方案1】:

    您需要做的是使用SO question 中提到的方法之一

    我的建议是在 Python 3 中使用 multiprocessing module

    【讨论】:

      猜你喜欢
      • 2023-03-24
      • 1970-01-01
      • 1970-01-01
      • 2017-09-09
      • 2018-08-22
      • 2019-04-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多