在python中分离firestore侦听器会导致程序冻结
下面是一个简单的测试代码,其中侦听器连接到firestore中的文档,然后分离在python中分离firestore侦听器会导致程序冻结,python,firebase,google-cloud-firestore,Python,Firebase,Google Cloud Firestore,下面是一个简单的测试代码,其中侦听器连接到firestore中的文档,然后分离 import firebase_admin from firebase_admin import credentials from firebase_admin import firestore cred = credentials.Certificate('Path to your credential file') firebase_admin.initialize_app(cred) def on_snap
import firebase_admin
from firebase_admin import credentials
from firebase_admin import firestore
cred = credentials.Certificate('Path to your credential file')
firebase_admin.initialize_app(cred)
def on_snapshot(doc_snapshot, changes, read_time):
for doc in doc_snapshot:
print(u'Received document snapshot: {}'.format(doc.id))
db = firestore.client()
doc_ref = db.collection('cities').document('SF')
doc_watch = doc_ref.on_snapshot(on_snapshot) # attaching listener
print('unsubscribing')
doc_watch.unsubscribe() # detaching listener
print('unsubscribed')
Listener工作得很好,但当涉及到分离时,程序只是在unsubscribe()调用时冻结。它不会给出任何错误或异常,经过一段时间后,情况是一样的。只有使键盘中断才能停止程序,我每次都会得到相同的回溯:
Traceback (most recent call last):
File "firestore_test.py", line 21, in <module>
doc_watch.unsubscribe()
File "/home/andriy/.local/lib/python3.6/site-packages/google/cloud/firestore_v1/watch.py", line 313, in unsubscribe
self.close()
File "/home/andriy/.local/lib/python3.6/site-packages/google/cloud/firestore_v1/watch.py", line 278, in close
self._consumer.stop()
File "/home/andriy/.local/lib/python3.6/site-packages/google/api_core/bidi.py", line 701, in stop
self._thread.join()
File "/usr/lib/python3.6/threading.py", line 1056, in join
self._wait_for_tstate_lock()
File "/usr/lib/python3.6/threading.py", line 1072, in _wait_for_tstate_lock
elif lock.acquire(block, timeout):
KeyboardInterrupt
回溯(最近一次呼叫最后一次):
文件“firestore_test.py”,第21行,在
doc_watch.unsubscribe()
文件“/home/andriy/.local/lib/python3.6/site packages/google/cloud/firestore_v1/watch.py”,第313行,在“取消订阅”中
self.close()
文件“/home/andriy/.local/lib/python3.6/site packages/google/cloud/firestore_v1/watch.py”,第278行,关闭
self.\u consumer.stop()
文件“/home/andriy/.local/lib/python3.6/site packages/google/api_core/bidi.py”,第701行,在stop中
self.\u thread.join()
文件“/usr/lib/python3.6/threading.py”,第1056行,在join中
self.\u等待状态锁定()
文件“/usr/lib/python3.6/threading.py”,第1072行,在等待状态锁中
elif lock.acquire(块,超时):
键盘中断
这是一个未解决的问题,请参见最近修复并关闭的问题。如何使用此修复程序获得较新版本的python客户端?谢谢,很遗憾,我不确定。现在,我将把unsubscribe()
保留到下一个版本。否则,我认为这可能描述了如何使用github中的库?当我尝试使用github的库时,我注意到有新版本的GoogleAPI核心。并与新版本(1.14.3)退订工程。非常感谢这是一个开放的问题,请看它最近被修复和关闭。如何使用此修复程序获得较新版本的python客户端?谢谢,很遗憾,我不确定。现在,我将把unsubscribe()
保留到下一个版本。否则,我认为这可能描述了如何使用github中的库?当我尝试使用github的库时,我注意到有新版本的GoogleAPI核心。并与新版本(1.14.3)退订工程。多谢各位