-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Pub/Sub: return typefuture
is not concurrent.futures.Future
#6201
Comments
@theacodes can you comment? |
Yeah we should update it. It should additionally say that it conforms to the |
Thanks! Listing a couple of places in the doc where publisher |
I have actually got another case where the returned future not being a |
@himikof we can't inherit from concurent.futures.Future because it brings in a ton of stuff. I'm happy for us to add utilities to make working across this stuff possible. It would be relatively low priority for us right now, but we would more than welcome contributions to get it done sooner. Thanks! |
If you end up here trying to figure out how to make a PubSub future act like a concurrent Future, hopefully this code snippet will help if __name__ == "__main__":
asyncio.set_event_loop(uvloop.new_event_loop())
s1 = app.create_server(host="0.0.0.0", port=8090)
task = asyncio.ensure_future(s1)
print('creating subscription to pubsub')
pubsub_future = subscriber.subscribe(subscription_path, callback=callback)
# this is not really a future
# so monkey patch
pubsub_future._asyncio_future_blocking = True
pubsub_future.__class__._asyncio_future_blocking = True
s2 = asyncio.wrap_future(pubsub_future)
task2 = asyncio.ensure_future(s2)
try:
loop.run_forever()
except:
loop.stop() |
@sam-qordoba What is a |
Ahh sorry, that was some code I had for using asyncio to run a Sanic web server and pubsub listener in the same process. The main part is pubsub_future = subscriber.subscribe(
subscription_path,
callback=callback)
# Google implemented a custom, psuedo-future
# need monkey patch for it to work with asyncio
pubsub_future._asyncio_future_blocking = True
pubsub_future.__class__._asyncio_future_blocking = True
real_pubsub_future = asyncio.wrap_future(pubsub_future) |
google-cloud-python/pubsub/google/cloud/pubsub_v1/publisher/client.py
Line 170 in 8f63393
Contrary to what's in the reference, the correct return type for
publish()
should begoogle.cloud.pubsub_v1.publisher.futures.Future
. I didn't find a reference for it but only some reference forgoogle.cloud.pubsub_v1.subscriber.futures.StreamingPullFuture
.People won't be able to use of Python's concurrent library's
wait()
method ongoogle.cloud.pubsub_v1.publisher.futures.Future
. But our doc implies they can because we say the return type isconcurrent.futures.Future
.Here is the error:
I tried in both Python 2 and 3.
The text was updated successfully, but these errors were encountered: