Skip to content

Make publish futures compatible with concurrent.futures.as_completed() #368

@mbrancato

Description

@mbrancato

Environment details

  • OS type and version: Linux
  • Python version: Python 3.7.7
  • pip version: pip 21.0.1
  • google-cloud-pubsub version:
Version: 2.3.0
Summary: Google Cloud Pub/Sub API client library
Home-page: https://github.com/googleapis/python-pubsub
Author: Google LLC
Author-email: googleapis-packages@google.com
License: Apache 2.0
Location: /Users/mike/.pyenv/versions/3.8.6/envs/detection-processor/lib/python3.8/site-packages
Requires: grpc-google-iam-v1, proto-plus, google-api-core, libcst
Required-by: 

Steps to reproduce

  1. Create multiple publish futures with publisher.publish()
  2. Use in concurrent.futures.as_completed() as a generator to trigger on completion.

Code example

future_list = []

for msg in messages:
    future_list.append(publisher.publish(topic_path, msg))

for _ in concurrent.futures.as_completed(
    fs=future_list,
):
    # Do something
    continue

Stack trace

'Future' object has no attribute '_condition'

I understand that the publish future is not REALLY a concurrent future object. This attribute error does not happen with all messages, it's a minority of messages. I'm not sure what causes some publish futures to work with as_completed and some do not.

Metadata

Metadata

Assignees

Labels

api: pubsubIssues related to the googleapis/python-pubsub API.type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions