Title: Retry decorator should support generator functions · Issue #485 · googleapis/python-api-core · GitHub
Open Graph Title: Retry decorator should support generator functions · Issue #485 · googleapis/python-api-core
X Title: Retry decorator should support generator functions · Issue #485 · googleapis/python-api-core
Description: 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 st...
Open Graph Description: 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 nee...
X Description: 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 nee...
Opengraph URL: https://github.com/googleapis/python-api-core/issues/485
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Retry decorator should support generator functions","articleBody":" **Is your feature request related to a problem? Please describe.**\r\n\r\nServer streaming libraries [return an iterable](https://github.com/googleapis/python-bigtable/blob/a6cfb021e1b158b81879b115868112875b1e4162/google/cloud/bigtable_v2/services/bigtable/client.py#L471) 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.\r\n\r\nIt would be useful to wrap this whole pipeline in a [retry decorator](https://github.com/googleapis/python-api-core/blob/b8e75cff8bf6772ab76ca6f8d3c80dc2580075c7/google/api_core/retry.py#L222), so that if the stream breaks mid-way through, we can recover and continue yielding data through our generator as if nothing happened. \r\n\r\nUnfortunately, the [current implementation ](https://github.com/googleapis/python-api-core/blob/b8e75cff8bf6772ab76ca6f8d3c80dc2580075c7/google/api_core/retry.py#L191) returns the result of the target function directly, so generators will not yield values and exceptions through the retry block\r\n\r\n **Describe the solution you'd like**\r\n\r\nAdd some code to detect when a target function is a generator. If so, Replace: https://github.com/googleapis/python-api-core/blob/b8e75cff8bf6772ab76ca6f8d3c80dc2580075c7/google/api_core/retry.py#L191\r\nwith:\r\n```\r\nyield from target()\r\n```\r\n\r\nSome extra work will also be needed to detect generator `.close()`, and async generators\r\n\r\nI plan on putting together a PR for this shortly","author":{"url":"https://github.com/daniel-sanche","@type":"Person","name":"daniel-sanche"},"datePublished":"2023-02-10T21:01:39.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/485/python-api-core/issues/485"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:1a05bac1-10e2-0a5a-7416-3eae50da98f8 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8878:3092B8:B522D0:B91A1A:6A4DB74C |
| html-safe-nonce | 8032e63f29c4b2bfa80465d17d18b2bb5fed5659dfbcfba4ced8f2c24662163c |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4ODc4OjMwOTJCODpCNTIyRDA6QjkxQTFBOjZBNERCNzRDIiwidmlzaXRvcl9pZCI6IjExMDE2Nzc0MjI2NTMwNjA5NDAiLCJyZWdpb25fZWRnZSI6InNlYSIsInJlZ2lvbl9yZW5kZXIiOiJzZWEifQ== |
| visitor-hmac | 3259b863f082afec94c2ea847c31ae87689a8022687309cf88df8837072c9be2 |
| hovercard-subject-tag | issue:1580324658 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/googleapis/python-api-core/485/issue_layout |
| twitter:image | https://opengraph.githubassets.com/d88ae01004f1c31ea0194f784f2d8019c64961c50e7a8b3a25fbf5272888a0d6/googleapis/python-api-core/issues/485 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/d88ae01004f1c31ea0194f784f2d8019c64961c50e7a8b3a25fbf5272888a0d6/googleapis/python-api-core/issues/485 |
| og:image:alt | 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 nee... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | daniel-sanche |
| hostname | github.com |
| expected-hostname | github.com |
| None | 06b8a6144231bf3a234f1c2e9993861e07ce98a905912b114aa386c2d7e84b33 |
| turbo-cache-control | no-preview |
| go-import | github.com/googleapis/python-api-core git https://github.com/googleapis/python-api-core.git |
| octolytics-dimension-user_id | 16785467 |
| octolytics-dimension-user_login | googleapis |
| octolytics-dimension-repository_id | 226992456 |
| octolytics-dimension-repository_nwo | googleapis/python-api-core |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 226992456 |
| octolytics-dimension-repository_network_root_nwo | googleapis/python-api-core |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 32f7b614aca06e6bbd89842b1370df1328264f68 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width