Retry decorator should support generator functions #485
Labels
priority: p2
Moderately-important priority. Fix may not be included in next release.
type: feature request
‘Nice-to-have’ improvement, new feature or different behavior or design.
Is your feature request related to a problem? Please describe.
Server streaming libraries return an iterable that can asynchronously yield data from the backend over time. Some of our libraries need to provide a wrapper around the raw stream to do some local processing, before passing the data to the user.
It would be useful to wrap this whole pipeline in a retry decorator, so that if the stream breaks mid-way through, we can recover and continue yielding data through our generator as if nothing happened.
Unfortunately, the current implementation returns the result of the target function directly, so generators will not yield values and exceptions through the retry block
Describe the solution you'd like
Add some code to detect when a target function is a generator. If so, Replace:
python-api-core/google/api_core/retry.py
Line 191 in b8e75cf
with:
Some extra work will also be needed to detect generator
.close()
, and async generatorsI plan on putting together a PR for this shortly
The text was updated successfully, but these errors were encountered: