Title: Simplify consumers with iteration over `*.Queue` · Issue #120947 · python/cpython · GitHub
Open Graph Title: Simplify consumers with iteration over `*.Queue` · Issue #120947 · python/cpython
X Title: Simplify consumers with iteration over `*.Queue` · Issue #120947 · python/cpython
Description: Feature or enhancement Proposal: Currently consuming items from a queue can be a bit more complex than necessary. You need to use an infinite while loop check for a sentinel or add all worker tasks to a list call q.task_done() after proc...
Open Graph Description: Feature or enhancement Proposal: Currently consuming items from a queue can be a bit more complex than necessary. You need to use an infinite while loop check for a sentinel or add all worker tasks...
X Description: Feature or enhancement Proposal: Currently consuming items from a queue can be a bit more complex than necessary. You need to use an infinite while loop check for a sentinel or add all worker tasks...
Opengraph URL: https://github.com/python/cpython/issues/120947
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Simplify consumers with iteration over `*.Queue`","articleBody":"# Feature or enhancement\r\n\r\n### Proposal:\r\n\r\nCurrently consuming items from a queue can be a bit more complex than necessary. You need to\r\n\r\n1. use an infinite while loop\r\n2. check for a sentinel or add all worker tasks to a list\r\n3. call `q.task_done()` after processing each item\r\n4. join the queue\r\n5. cancel all worker tasks\r\n6. wait until all worker tasks are cancelled\r\n\r\nBy allowing iteration over `*.Queue`, this becomes a bit easier, you only need to call `queue.shutdown()`.\r\n\r\n### Has this already been discussed elsewhere?\r\n\r\nNo response given\r\n\r\n### Links to previous discussion of this feature:\r\n\r\n- #119154\r\n- #120499\r\n- #120924\r\n\r\n\u003c!-- gh-linked-prs -->\r\n### Linked PRs\r\n- **Implementation A**: add `asyncio.Queue.__aiter__()` and `queue.Queue.__iter__()`\r\n * gh-120491\r\n * gh-120503\r\n- **Implementation B**: add `*.Queue.iter()` and `*.Queue.iter_nowait()`\r\n * gh-120925\r\n\u003c!-- /gh-linked-prs -->\r\n","author":{"url":"https://github.com/nineteendo","@type":"Person","name":"nineteendo"},"datePublished":"2024-06-24T13:06:55Z","url":"https://github.com/python/cpython/issues/120947"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| 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:327a206e-bdbc-57aa-4d79-0031fdc55b60 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | AEFA:2E3FEE:4A2F504:5DAC1C3:6B024A68 |
| html-safe-nonce | cc05a03eaca886759c1381e7d565d87db08326fed8c22444c21f9c6a117bb169 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBRUZBOjJFM0ZFRTo0QTJGNTA0OjVEQUMxQzM6NkIwMjRBNjgiLCJ2aXNpdG9yX2lkIjoiMzU1NzU5MDM2NDQ3NzA4MjIxNiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 06dc3d10a41b51069630327c2ed26aaecf73fd86464e89ed03baa0bcf7c0eb1b |
| hovercard-subject-tag | issue:2370213396 |
| 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/python/cpython/120947/issue_layout |
| twitter:image | https://opengraph.githubassets.com/56236df07e228fa8a37eb5e32a2f106a516e5db8f23c9ca6f82ab8648acbae63/python/cpython/issues/120947 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/56236df07e228fa8a37eb5e32a2f106a516e5db8f23c9ca6f82ab8648acbae63/python/cpython/issues/120947 |
| og:image:alt | Feature or enhancement Proposal: Currently consuming items from a queue can be a bit more complex than necessary. You need to use an infinite while loop check for a sentinel or add all worker tasks... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | nineteendo |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| 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 | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width