René's URL Explorer Experiment


Title: 3.12 regression: interpreter shouldn't shut down when there are non-daemon threads left · Issue #115533 · python/cpython · GitHub

Open Graph Title: 3.12 regression: interpreter shouldn't shut down when there are non-daemon threads left · Issue #115533 · python/cpython

X Title: 3.12 regression: interpreter shouldn't shut down when there are non-daemon threads left · Issue #115533 · python/cpython

Description: Bug report Bug description: This is related to #113964, but trying to address the bigger problem of what "interpreter shutdown" is, and trying to make a stronger case for restoring the old behavior. TL;DR: This was an undocumented change...

Open Graph Description: Bug report Bug description: This is related to #113964, but trying to address the bigger problem of what "interpreter shutdown" is, and trying to make a stronger case for restoring the old behavior...

X Description: Bug report Bug description: This is related to #113964, but trying to address the bigger problem of what "interpreter shutdown" is, and trying to make a stronger case for restoring the ol...

Opengraph URL: https://github.com/python/cpython/issues/115533

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"3.12 regression: interpreter shouldn't shut down when there are non-daemon threads left","articleBody":"# Bug report\r\n\r\n### Bug description:\r\n\r\nThis is related to #113964, but trying to address the bigger problem of what \"interpreter shutdown\" is, and trying to make a stronger case for restoring the old behavior.\r\n\r\nTL;DR: This was an undocumented change. The old behavior was useful. Documentation is contradictory. Users are struggling and are recommended to downgrade.\r\n\r\n### Undocumented change\r\n\r\nIn Python 3.11 and previous versions, `daemon=False` threads could spawn new threads even after the main thread has exited.\r\n\r\nThis changed in Python 3.12, which throws \"**RuntimeError: can't create new thread at interpreter shutdown**\" when a `daemon=False` thread tries to spawn new threads after the main thread has exited.\r\n\r\nI could not find this change to be documented in 3.12 release notes, it appears to be an unintentional change.\r\n\r\n### Reproducer\r\n\r\n```python\r\n\"\"\"Python 3.11: Successfully spawns 20 subthreads. Python 3.12: RuntimeError.\"\"\"\r\nfrom threading import Thread, current_thread\r\nfrom time import sleep\r\n\r\ndef subthread():\r\n    print(f\"Thread {current_thread().name} spawned...\")\r\n\r\ndef thread():\r\n    for i in range(20):\r\n        Thread(target=subthread, daemon=False).start()\r\n        sleep(0.001)\r\n\r\nThread(target=thread, daemon=False).start()\r\n```\r\n\r\n### Old behavior was useful\r\n\r\nWhile not `join()`ing the launched threads is considered an antipattern, at the very least the old behavior was useful for throw-away scripts that launch a bunch of threads, and have Python exit automatically once all work was finished.\r\n\r\n### Documentation is contradictory\r\n\r\nThe [documentation says this about daemon threads](https://docs.python.org/3/library/threading.html#thread-objects):\r\n\r\n\u003e A thread can be flagged as a “daemon thread”. The significance of this flag is that the entire Python program **exits when only daemon threads are left**.\r\n\r\nI think a useful interpretation of \"exits when only daemon threads are left\" also implies \"the Python program starts shutting down when only daemon threads are left\", and does not shut down before. Because what else could \"exits\" mean if not \"shuts down\"?\r\n\r\nAlthough this is in conflict with [the definition of \"interpreter shutdown\"](https://docs.python.org/3/glossary.html#term-interpreter-shutdown) that states:\r\n\r\n\u003e The main reason for interpreter shutdown is that the `__main__` module or the script being run has finished executing.\r\n\r\nThis interpetation is also not being respected by `sys.is_finalizing()` API. This is supposed to \"Return True if the Python interpreter is shutting down\", but it returns False in this situation even after the main thread has exited and thread spawning fails: #114570. That's another indication that this change was unintentional.\r\n\r\n### Users are struggling\r\n\r\nPython has a reputation for breakage across version upgrades. I hope there is motivation among CPython developers to change that. I think such unintentional changes that break users, should be treated as regressions to be fixed.\r\n\r\nThere are three posts on StackOverflow [[1]](https://stackoverflow.com/questions/77631477/runtimeerror-cant-create-new-thread-at-interpreter-shutdown-python-3-12) [[2]](https://stackoverflow.com/questions/77862839/runtimeerror-cant-create-new-thread-at-interpreter-shutdown-while-it-works-per) [[3]](https://stackoverflow.com/questions/77738120/runtimeerror-cant-create-new-thread-at-interpreter-shutdown), where downgrading Python is the dominant \"solution\". And when you have threads spawning more threads, the \"proper fix\" is often not a simple matter of adding a `Thread.join()` somewhere, but may require re-architecting the whole program to keep track of what all threads are doing.\r\n\r\nRelated issues: #113964, #114570.\r\n\r\n### CPython versions tested on:\r\n\r\n3.12.2, 3.11.7\r\n\r\n### Operating systems tested on:\r\n\r\nLinux, macOS","author":{"url":"https://github.com/intgr","@type":"Person","name":"intgr"},"datePublished":"2024-02-15T17:58:12.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":10},"url":"https://github.com/115533/cpython/issues/115533"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:a9385d81-c90c-957f-0f07-77c0c84e787d
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idA418:10F1EB:40006E:5A41BA:696A15B7
html-safe-noncedd808770207f58f5cae3bbb2b11073e88ff5bc8a6a3e42bac0b8f241632cf5ac
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBNDE4OjEwRjFFQjo0MDAwNkU6NUE0MUJBOjY5NkExNUI3IiwidmlzaXRvcl9pZCI6IjU5NTA3MTAyOTE2ODk1MTAzMjciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac84dffb3fd7775a191eedd2f8708a282945d774d011553e94dc3065a582cddcf9
hovercard-subject-tagissue:2137122132
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/115533/issue_layout
twitter:imagehttps://opengraph.githubassets.com/6e53930a1a59fc30799f66cc128e5e8df6b7af2df3adfc069f079c4cd8acd0bf/python/cpython/issues/115533
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/6e53930a1a59fc30799f66cc128e5e8df6b7af2df3adfc069f079c4cd8acd0bf/python/cpython/issues/115533
og:image:altBug report Bug description: This is related to #113964, but trying to address the bigger problem of what "interpreter shutdown" is, and trying to make a stronger case for restoring the old behavior...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameintgr
hostnamegithub.com
expected-hostnamegithub.com
None34a52bd10bd674f68e5c1b6b74413b79bf2ca20c551055ace3f7cdd112803923
turbo-cache-controlno-preview
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
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
releasee8bd37502700f365b18a4d39acf7cb7947e11b1a
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/python/cpython/issues/115533#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F115533
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub SparkBuild and deploy intelligent appshttps://github.com/features/spark
GitHub ModelsManage and compare promptshttps://github.com/features/models
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
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
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
GitHub SponsorsFund open source developershttps://github.com/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/accelerator
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://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/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F115533
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=python%2Fcpython
Reloadhttps://github.com/python/cpython/issues/115533
Reloadhttps://github.com/python/cpython/issues/115533
Reloadhttps://github.com/python/cpython/issues/115533
python https://github.com/python
cpythonhttps://github.com/python/cpython
Please reload this pagehttps://github.com/python/cpython/issues/115533
Notifications https://github.com/login?return_to=%2Fpython%2Fcpython
Fork 33.9k https://github.com/login?return_to=%2Fpython%2Fcpython
Star 71.1k https://github.com/login?return_to=%2Fpython%2Fcpython
Code https://github.com/python/cpython
Issues 5k+ https://github.com/python/cpython/issues
Pull requests 2.1k https://github.com/python/cpython/pulls
Actions https://github.com/python/cpython/actions
Projects 31 https://github.com/python/cpython/projects
Security Uh oh! There was an error while loading. Please reload this page. https://github.com/python/cpython/security
Please reload this pagehttps://github.com/python/cpython/issues/115533
Insights https://github.com/python/cpython/pulse
Code https://github.com/python/cpython
Issues https://github.com/python/cpython/issues
Pull requests https://github.com/python/cpython/pulls
Actions https://github.com/python/cpython/actions
Projects https://github.com/python/cpython/projects
Security https://github.com/python/cpython/security
Insights https://github.com/python/cpython/pulse
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/115533
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/115533
3.12 regression: interpreter shouldn't shut down when there are non-daemon threads lefthttps://github.com/python/cpython/issues/115533#top
3.12only security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.12%22
interpreter-core(Objects, Python, Grammar, and Parser dirs)https://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22interpreter-core%22
topic-subinterpretershttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-subinterpreters%22
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
https://github.com/intgr
https://github.com/intgr
intgrhttps://github.com/intgr
on Feb 15, 2024https://github.com/python/cpython/issues/115533#issue-2137122132
#113964https://github.com/python/cpython/issues/113964
documentation says this about daemon threadshttps://docs.python.org/3/library/threading.html#thread-objects
the definition of "interpreter shutdown"https://docs.python.org/3/glossary.html#term-interpreter-shutdown
#114570https://github.com/python/cpython/issues/114570
[1]https://stackoverflow.com/questions/77631477/runtimeerror-cant-create-new-thread-at-interpreter-shutdown-python-3-12
[2]https://stackoverflow.com/questions/77862839/runtimeerror-cant-create-new-thread-at-interpreter-shutdown-while-it-works-per
[3]https://stackoverflow.com/questions/77738120/runtimeerror-cant-create-new-thread-at-interpreter-shutdown
#113964https://github.com/python/cpython/issues/113964
#114570https://github.com/python/cpython/issues/114570
3.12only security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.12%22
interpreter-core(Objects, Python, Grammar, and Parser dirs)https://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22interpreter-core%22
topic-subinterpretershttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-subinterpreters%22
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
Threading issues 🧵https://github.com/orgs/python/projects/12
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.