googleapis / googleapis/google-cloud-python

Asyncio coroutines for common tasks

Aperta
#15,653 14 commenti 15 reazioni 1 assegnatario Rivendicata da @abbrowne126 Vedi su GitHub
api: pubsub type: feature request
Lingua principale
Python
Stelle
5.4k
Fork
1.8k
Merge medio
3g 4h
PR unite (30g)
122

Descrizione

The current status of asyncio has mostly been answered here already: https://github.com/googleapis/python-pubsub/issues/218#issuecomment-760778351

This feature request is to ask for a formal exposure of high-level awaitable methods for interacting with the PubSub library and reducing the use of threads. Although, if the library still wants to manage threads, that seems fine as long as how we use the library would be awaitable and the callback are run in the same event loop. I don't want to be too prescriptive on the implementation in my request.

Some examples, assuming `SubscriberClient` and `PublisherClient` were already setup...

example subscribe:

```python
async def my_func(msg):
# ... do something
pass

subscription_path = f"projects/{project_id}/subscriptions/{subscription}"
streaming_pull_async = subscriber.subscribe_async(subscription_path, callback=my_func,)

try:
await streaming_pull_async.result(timeout=pull_timeout)
except TimeoutError:
# Handle flow timeout
pass
```

example publish:

```python
topic_path = f"projects/{project_id}/topics/{output_topic}"
publish_value_async = publisher.publish_async(topic_path, value)
await publish_value_async.result()
```

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.