我有一个使用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创建了一个功能请求
发布于 2020-01-29 17:10:13
您需要做的是使用此SO question中提到的方法之一
我的建议是在Python3中使用multiprocessing module
https://stackoverflow.com/questions/59951848
复制相似问题