Skip to content

Pub/Sub: return typefuture is not concurrent.futures.Future  #6201

@anguillanneuf

Description

@anguillanneuf

~concurrent.futures.Future: An object conforming to the

Contrary to what's in the reference, the correct return type for publish() should be google.cloud.pubsub_v1.publisher.futures.Future. I didn't find a reference for it but only some reference for google.cloud.pubsub_v1.subscriber.futures.StreamingPullFuture.

People won't be able to use of Python's concurrent library's wait() method on google.cloud.pubsub_v1.publisher.futures.Future. But our doc implies they can because we say the return type is concurrent.futures.Future.

from concurrent.futures import wait
from google.cloud import pubsub_v1

publisher = pubsub_v1.PublisherClient()
# future has type `google.cloud.pubsub_v1.publisher.futures.Future`
future = publisher.publish('projects/{PROJECT_ID}/topics/{TOPIC_NAME}', data=b'rain')

# wait(fs, timeout=None, return_when='ALL_COMPLETED') expects a sequence of `concurrent.futures.Future`.  
wait([future])

Here is the error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.5/concurrent/futures/_base.py", line 257, in wait
    with _AcquireFutures(fs):
  File "/usr/lib/python3.5/concurrent/futures/_base.py", line 146, in __enter__
    future._condition.acquire()
AttributeError: 'Future' object has no attribute '_condition'

I tried in both Python 2 and 3.

Metadata

Metadata

Assignees

Labels

api: pubsubIssues related to the Pub/Sub API.type: questionRequest for information or clarification. Not an issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions