issue: publish future hangs when a context manager is not used
anguillanneuf opened this issue · 3 comments
anguillanneuf commented
Do we want to support both?
# This works.
with make_publisher(topic_path) as publisher_client:
api_future = publisher_client.publish(data.encode("utf-8"))
ack_id = api_future.result()
# This hangs.
publisher_client = make_publisher(topic_path)
api_future = publisher_client.publish(data.encode("utf-8"))
ack_id = api_future.result()
dpcollins-google commented
No. This is WAI. You need to call __enter__()
on the publisher. You can always do so manually by calling publisher_client.__enter__()
, but you need to call it.
anguillanneuf commented
I can add a comment in the sample. However, is this clear in the library documentation anywhere?
dpcollins-google commented
This should be clear from the fact that it overrides ContextManager, but I can add an additional comment documenting this.