René's URL Explorer Experiment


Title: gh-119154: Simplify consumers by making `queue.Queue` an iterable by nineteendo · Pull Request #120503 · python/cpython · GitHub

Open Graph Title: gh-119154: Simplify consumers by making `queue.Queue` an iterable by nineteendo · Pull Request #120503 · python/cpython

X Title: gh-119154: Simplify consumers by making `queue.Queue` an iterable by nineteendo · Pull Request #120503 · python/cpython

Description: Purpose Currently consuming items from a queue is very complex. You need to use an infinite while loop check for a sentinel call q.task_done() after processing each item join the queue cancel all worker tasks using sentinels By making queue.Queue an iterable, this becomes a lot easier, you only need to call q.shutdown(). Overview of changes Calling queue.Queue.__iter__() returns a generator which iterates over the queue of items An example has been added in the documentation which is a lot simpler than working with daemon threads Example Without iteration import concurrent.futures import queue import time def producer(q): for i in range(5): print(f'{i} -> queue') q.put(i) time.sleep(.1) def consumer(q): while True: i = q.get() if i is None: break print(f'queue -> {i}') time.sleep(.3) q.task_done() q = queue.Queue() with concurrent.futures.ThreadPoolExecutor() as tp1: tp1.submit(consumer, q) with concurrent.futures.ThreadPoolExecutor() as tp2: tp2.submit(producer, q) print('produced everything') q.join() q.put(None) print('consumed everything') With iteration import concurrent.futures import queue import time def producer(q): for i in range(5): print(f'{i} -> queue') q.put(i) time.sleep(.1) def consumer(q): for i in q: print(f'queue -> {i}') time.sleep(.3) q = queue.Queue() with concurrent.futures.ThreadPoolExecutor() as tp1: tp1.submit(consumer, q) with concurrent.futures.ThreadPoolExecutor() as tp2: tp2.submit(producer, q) q.shutdown() print('produced everything') print('consumed everything') Output 0 -> queue queue -> 0 1 -> queue 2 -> queue queue -> 1 3 -> queue 4 -> queue produced everything queue -> 2 queue -> 3 queue -> 4 consumed everything Issue: gh-119154 📚 Documentation preview 📚: library/queue.html

Open Graph Description: Purpose Currently consuming items from a queue is very complex. You need to use an infinite while loop check for a sentinel call q.task_done() after processing each item join the queue cancel all ...

X Description: Purpose Currently consuming items from a queue is very complex. You need to use an infinite while loop check for a sentinel call q.task_done() after processing each item join the queue cancel all ...

Opengraph URL: https://github.com/python/cpython/pull/120503

X: @github

direct link

Domain: github.com

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:232ff8f2-1e5b-17cf-ac7a-558197b6811c
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idE04E:240CD1:4837D40:5B99A45:6B024A8B
html-safe-nonceae4f254157411488c1695997338f801c6300d31949dd573522755914ac99c6ff
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFMDRFOjI0MENEMTo0ODM3RDQwOjVCOTlBNDU6NkIwMjRBOEIiLCJ2aXNpdG9yX2lkIjoiMjQ4MjE2ODk0MTk3NjM3Mzg5OSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmacfc2928dd3899c88929631a7321829cad6c1c0a25ff79b47b78542f6c3ae8e8e7
hovercard-subject-tagpull_request:1920711916
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/files
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/python/cpython/pull/120503/files
twitter:imagehttps://avatars.githubusercontent.com/u/65588599?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/65588599?s=400&v=4
og:image:altPurpose Currently consuming items from a queue is very complex. You need to use an infinite while loop check for a sentinel call q.task_done() after processing each item join the queue cancel all ...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
None87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456
turbo-cache-controlno-preview
diff-viewunified
go-importgithub.com/python/cpython git https://github.com/python/cpython.git
octolytics-dimension-user_id1525981
octolytics-dimension-user_loginpython
octolytics-dimension-repository_id81598961
octolytics-dimension-repository_nwopython/cpython
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id81598961
octolytics-dimension-repository_network_root_nwopython/cpython
turbo-body-classeslogged-out env-production page-responsive full-width
disable-turbotrue
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release423dbb54c5e7bfecc838eb387c1435eb3d0e760d
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/python/cpython/pull/120503/files#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fpull%2F120503%2Ffiles
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fpull%2F120503%2Ffiles
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fpull_requests%2Fshow%2Ffiles&source=header-repo&source_repo=python%2Fcpython
Reloadhttps://github.com/python/cpython/pull/120503/files
Reloadhttps://github.com/python/cpython/pull/120503/files
Reloadhttps://github.com/python/cpython/pull/120503/files
pythonhttps://github.com/python
cpythonhttps://github.com/python/cpython
Codehttps://github.com/python/cpython
Issues5k+ (5k+)https://github.com/python/cpython/issues
Pull requests2.4k (2.4k)https://github.com/python/cpython/pulls
Actionshttps://github.com/python/cpython/actions
Projectshttps://github.com/python/cpython/projects
Security and qualityhttps://github.com/python/cpython/security
Insightshttps://github.com/python/cpython/insights
Sign up for GitHub https://github.com/signup?return_to=%2Fpython%2Fcpython%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2Fpython%2Fcpython%2Fissues%2Fnew%2Fchoose
nineteendohttps://github.com/nineteendo
python:mainhttps://github.com/python/cpython/tree/main
nineteendo:add-Queue.__iter__https://github.com/nineteendo/cpython/tree/add-Queue.__iter__
Conversation 19 https://github.com/python/cpython/pull/120503
Commits 27 https://github.com/python/cpython/pull/120503/commits
Checks 0 https://github.com/python/cpython/pull/120503/checks
Files changed https://github.com/python/cpython/pull/120503/files
Please reload this pagehttps://github.com/python/cpython/pull/120503/files
gh-119154: Simplify consumers by making queue.Queue an iterable https://github.com/python/cpython/pull/120503/files#top
Show all changes 27 commits https://github.com/python/cpython/pull/120503/files
e826a01 Add `queue.Queue.__iter__()` nineteendo Jun 14, 2024 https://github.com/python/cpython/pull/120503/commits/e826a01248a840f05182c97536f85e089ec584cf
c8cbe4d Add `asyncio.Queue.__iter__()` nineteendo Jun 14, 2024 https://github.com/python/cpython/pull/120503/commits/c8cbe4d0b1a48d31bfaa2dba3f3874c679a02dbe
940e3c0 📜🤖 Added by blurb_it. blurb-it[bot] Jun 14, 2024 https://github.com/python/cpython/pull/120503/commits/940e3c0ee41835d62771bfaf00dfc3168ea1206c
8fca288 Fix lint nineteendo Jun 14, 2024 https://github.com/python/cpython/pull/120503/commits/8fca2888da1ae26bf442723b922617be76b2f1e2
499457c Wait nineteendo Jun 14, 2024 https://github.com/python/cpython/pull/120503/commits/499457c1993c69f6cf7ff33ac94dcf082fc6b039
7f206d9 Update 2024-06-14-13-37-45.gh-issue-120499.JK7Mv8.rst nineteendo Jun 14, 2024 https://github.com/python/cpython/pull/120503/commits/7f206d98a7928a4531a84082d5874e8b6296d0f6
3cad181 Move while loop inside try/except block nineteendo Jun 18, 2024 https://github.com/python/cpython/pull/120503/commits/3cad1810cbe41fd88c1e8ce5244d152b5156e028
cc9f7ef test iteration nineteendo Jun 18, 2024 https://github.com/python/cpython/pull/120503/commits/cc9f7ef91dd4d89165ba8410a6ad144e222915b2
92d7dc0 Reduce diff nineteendo Jun 18, 2024 https://github.com/python/cpython/pull/120503/commits/92d7dc025519c526caa92c4bf8a851db5ffcd884
a92e031 Run test nineteendo Jun 18, 2024 https://github.com/python/cpython/pull/120503/commits/a92e0318f86d017b831aabf58def4b1feb3fd861
3621cc1 Reduce diff nineteendo Jun 18, 2024 https://github.com/python/cpython/pull/120503/commits/3621cc169d06928f11870944d72089dceb533638
98252c6 Adapt example from asyncio nineteendo Jun 18, 2024 https://github.com/python/cpython/pull/120503/commits/98252c6e925d85fc988cd19b51621d3d478b0970
4b1ff4b Simpler example nineteendo Jun 18, 2024 https://github.com/python/cpython/pull/120503/commits/4b1ff4ba47578fdb68e91b6a05325a00ddbd78c3
5e9f48b Put definition first nineteendo Jun 18, 2024 https://github.com/python/cpython/pull/120503/commits/5e9f48b76d5d652447761601833b5ad61ed61760
4b382ec Print worker name nineteendo Jun 18, 2024 https://github.com/python/cpython/pull/120503/commits/4b382ec300702fe85a60f49ab5e78e98df8bd360
076a7a6 Restore example nineteendo Jun 18, 2024 https://github.com/python/cpython/pull/120503/commits/076a7a617f5c62d558f364453003a95e51c05bf5
6132f5a Indent example nineteendo Jun 18, 2024 https://github.com/python/cpython/pull/120503/commits/6132f5a854eb3caa771f6fc66aa1d0f9262fd59b
9a28bc5 Cleanup tests nineteendo Jun 18, 2024 https://github.com/python/cpython/pull/120503/commits/9a28bc508f5afb28946c40b7581ff3c54afc9102
0a69fd9 Instantiate nineteendo Jun 18, 2024 https://github.com/python/cpython/pull/120503/commits/0a69fd9752bc02aa11ac6a65b6cd8a22cd486b1c
4407eed Move inside with block nineteendo Jun 18, 2024 https://github.com/python/cpython/pull/120503/commits/4407eedd34f008d08b64377594a24f1d871422bc
1e500ab Add comment nineteendo Jun 18, 2024 https://github.com/python/cpython/pull/120503/commits/1e500abcd7aa2e4c2636d67846c4550eba75fd6a
101409f Separate function definition nineteendo Jun 18, 2024 https://github.com/python/cpython/pull/120503/commits/101409f316e6fd93ccfa139336eaa0a0857b6ef8
bcdb21f Update whatsnew nineteendo Jun 19, 2024 https://github.com/python/cpython/pull/120503/commits/bcdb21ff04df988175b9d4edc53ae22c2a00d4c3
0743257 Update blurb nineteendo Jun 19, 2024 https://github.com/python/cpython/pull/120503/commits/0743257f2dba19d6b163124361da3ff9f0a1ac52
5e37cd5 Rename 2024-06-14-13-37-45.gh-issue-120499.JK7Mv8.rst to 2024-06-14-1… nineteendo Jun 19, 2024 https://github.com/python/cpython/pull/120503/commits/5e37cd5ea45504c870e192e77312bf3b17c446d9
1f05869 Merge branch 'main' into add-Queue.__iter__ nineteendo Jun 19, 2024 https://github.com/python/cpython/pull/120503/commits/1f058690c5c5d45acc6c55d1127a5ae78719778b
b23a1b3 Clarify documentation nineteendo Jun 21, 2024 https://github.com/python/cpython/pull/120503/commits/b23a1b326791edd0b4310867c12bce008e7b2656
Clear filters https://github.com/python/cpython/pull/120503/files
Please reload this pagehttps://github.com/python/cpython/pull/120503/files
Please reload this pagehttps://github.com/python/cpython/pull/120503/files
queue.rst https://github.com/python/cpython/pull/120503/files#diff-5f8aec8fa45976df3a34d74ef406e3c373a0e02a978dd5d8c8d824a6783eafef
3.14.rst https://github.com/python/cpython/pull/120503/files#diff-24e6cbe61d91e61059c44a7cf5f712499a11eb47a82d5f1a8db16ec7f9023c31
queue.py https://github.com/python/cpython/pull/120503/files#diff-aefad8744bccb805db2835af233fae516b8824a1e4d20b2545a640278c69620d
test_queue.py https://github.com/python/cpython/pull/120503/files#diff-aa2555f5532a7deb4b049d0b1f6b45f79bdcc9e4479548d930c09b2720fe0181
2024-06-14-13-37-45.gh-issue-120499.JK7Mv8.rst https://github.com/python/cpython/pull/120503/files#diff-1b963fcfc782c9467a05d2db1ea724c004f5ecd4ea08506f15a6f99719f7fb5d
Doc/library/queue.rsthttps://github.com/python/cpython/pull/120503/files#diff-5f8aec8fa45976df3a34d74ef406e3c373a0e02a978dd5d8c8d824a6783eafef
View file https://github.com/nineteendo/cpython/blob/b23a1b326791edd0b4310867c12bce008e7b2656/Doc/library/queue.rst
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/120503/{{ revealButtonHref }}
https://github.com/python/cpython/pull/120503/files#diff-5f8aec8fa45976df3a34d74ef406e3c373a0e02a978dd5d8c8d824a6783eafef
https://github.com/python/cpython/pull/120503/files#diff-5f8aec8fa45976df3a34d74ef406e3c373a0e02a978dd5d8c8d824a6783eafef
https://github.com/python/cpython/pull/120503/files#diff-5f8aec8fa45976df3a34d74ef406e3c373a0e02a978dd5d8c8d824a6783eafef
https://github.com/python/cpython/pull/120503/files#diff-5f8aec8fa45976df3a34d74ef406e3c373a0e02a978dd5d8c8d824a6783eafef
https://github.com/python/cpython/blob/main/.github/CODEOWNERS#L116
Doc/whatsnew/3.14.rsthttps://github.com/python/cpython/pull/120503/files#diff-24e6cbe61d91e61059c44a7cf5f712499a11eb47a82d5f1a8db16ec7f9023c31
View file https://github.com/nineteendo/cpython/blob/b23a1b326791edd0b4310867c12bce008e7b2656/Doc/whatsnew/3.14.rst
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/120503/{{ revealButtonHref }}
https://github.com/python/cpython/pull/120503/files#diff-24e6cbe61d91e61059c44a7cf5f712499a11eb47a82d5f1a8db16ec7f9023c31
https://github.com/python/cpython/pull/120503/files#diff-24e6cbe61d91e61059c44a7cf5f712499a11eb47a82d5f1a8db16ec7f9023c31
Lib/queue.pyhttps://github.com/python/cpython/pull/120503/files#diff-aefad8744bccb805db2835af233fae516b8824a1e4d20b2545a640278c69620d
View file https://github.com/nineteendo/cpython/blob/b23a1b326791edd0b4310867c12bce008e7b2656/Lib/queue.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/120503/{{ revealButtonHref }}
https://github.com/python/cpython/pull/120503/files#diff-aefad8744bccb805db2835af233fae516b8824a1e4d20b2545a640278c69620d
https://github.com/python/cpython/pull/120503/files#diff-aefad8744bccb805db2835af233fae516b8824a1e4d20b2545a640278c69620d
Lib/test/test_queue.pyhttps://github.com/python/cpython/pull/120503/files#diff-aa2555f5532a7deb4b049d0b1f6b45f79bdcc9e4479548d930c09b2720fe0181
View file https://github.com/nineteendo/cpython/blob/b23a1b326791edd0b4310867c12bce008e7b2656/Lib/test/test_queue.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/120503/{{ revealButtonHref }}
https://github.com/python/cpython/pull/120503/files#diff-aa2555f5532a7deb4b049d0b1f6b45f79bdcc9e4479548d930c09b2720fe0181
https://github.com/python/cpython/pull/120503/files#diff-aa2555f5532a7deb4b049d0b1f6b45f79bdcc9e4479548d930c09b2720fe0181
https://github.com/python/cpython/pull/120503/files#diff-aa2555f5532a7deb4b049d0b1f6b45f79bdcc9e4479548d930c09b2720fe0181
https://github.com/python/cpython/pull/120503/files#diff-aa2555f5532a7deb4b049d0b1f6b45f79bdcc9e4479548d930c09b2720fe0181
Misc/NEWS.d/next/Library/2024-06-14-13-37-45.gh-issue-120499.JK7Mv8.rsthttps://github.com/python/cpython/pull/120503/files#diff-1b963fcfc782c9467a05d2db1ea724c004f5ecd4ea08506f15a6f99719f7fb5d
View file https://github.com/nineteendo/cpython/blob/b23a1b326791edd0b4310867c12bce008e7b2656/Misc/NEWS.d/next/Library/2024-06-14-13-37-45.gh-issue-120499.JK7Mv8.rst
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/120503/{{ revealButtonHref }}
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.