-
Notifications
You must be signed in to change notification settings - Fork 75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Background thread did not exit when unsubscribing from watch #482
Comments
It seems this should be moved to the python-firestore repo. |
I can reproduce with some tweaks on my Linux system: $ python3.9 -m venv /tmp/repro-firestore-482
$ cd /tmp/repro-firestore-482/
$ bin/pip install --upgrade setuptools pip
...
Successfully installed pip-21.3.1 setuptools-59.1.1
$ bin/pip install google-cloud-firestore
...
Successfully installed cachetools-4.2.4 certifi-2021.10.8 charset-normalizer-2.0.7 google-api-core-2.2.2 google-auth-2.3.3 google-cloud-core-2.2.1 google-cloud-firestore-2.3.4 googleapis-common-protos-1.53.0 grpcio-1.42.0 grpcio-status-1.42.0 idna-3.3 packaging-21.3 proto-plus-1.19.8 protobuf-3.19.1 pyasn1-0.4.8 pyasn1-modules-0.2.8 pyparsing-3.0.6 requests-2.26.0 rsa-4.7.2 six-1.16.0 urllib3-1.26.7
$ cat repro_firestore_482.py
import threading
from google.cloud import firestore
db = firestore.Client()
doc_ref = db.collection('repro-firestore-482').document('sample')
callback_done = threading.Event()
def on_snapshot(doc_snapshot, changes, read_time):
for doc in doc_snapshot:
print(doc.to_dict())
callback_done.set()
doc_watch = doc_ref.on_snapshot(on_snapshot)
doc_ref.set({"sample": "data"})
callback_done.wait(10)
doc_watch.unsubscribe()
$ export GOOGLE_APPLICATION_CREDENTIALS=/path/to/service_account_creds.json
$ bin/python repro_firestore_482.py
{'sample': 'data'}
Background thread did not exit. |
I added the following line to configure logging: logging.basicConfig(level=logging.DEBUG) Which resulted in this output:
The logging is coming from the def stop(self):
"""Stop consuming the stream and shutdown the background thread."""
with self._operational_lock:
self._bidi_rpc.close()
if self._thread is not None:
# Resume the thread to wake it up in case it is sleeping.
self.resume()
# The daemonized thread may itself block, so don't wait
# for it longer than a second.
self._thread.join(1.0)
if self._thread.is_alive(): # pragma: NO COVER
_LOGGER.warning("Background thread did not exit.")
self._thread = None So, it looks to me like we don't have a bug here for firestore: instead, we have a possibly-annoying-but-expected warning emitted by |
Environment details
Steps to reproduce
Error
Background thread did not exit when unsubscribing from watch
The text was updated successfully, but these errors were encountered: