【发布时间】:2020-06-06 22:04:46
【问题描述】:
我有一个 python 脚本,它基于此处给出的示例: https://firebase.google.com/docs/firestore/manage-data/transactions
即:
transaction = db.transaction()
city_ref = db.collection(u'cities').document(u'SF')
@firestore.transactional
def update_in_transaction(transaction, city_ref):
snapshot = city_ref.get(transaction=transaction)
transaction.update(city_ref, {
u'population': snapshot.get(u'population') + 1
})
update_in_transaction(transaction, city_ref)
我找不到任何关于事务装饰器详细功能的好的文档(除了标记应该在事务中执行的内容),但似乎每当我尝试从新线程进行调用时,它都会卡住我还没有想出一个解释:
//Works fine if called like this
update_in_transaction(transaction, city_ref)
//Does NOT work if called like this:
threading.Thread(target=self.__my_method_to_start_the_transaction)
这是有问题的,因为它阻塞了我的 UI 线程并且我无法呈现任何加载指示器等。有什么建议吗?我错过了什么吗?
非常感谢!
【问题讨论】:
标签: python multithreading firebase google-cloud-firestore