René's URL Explorer Experiment


Title: GitHub · Where software is built

Open Graph Title: python/cpython

X Title: python/cpython

Description: The Python programming language. Contribute to python/cpython development by creating an account on GitHub.

Open Graph Description: The Python programming language. Contribute to python/cpython development by creating an account on GitHub.

X Description: The Python programming language. Contribute to python/cpython development by creating an account on GitHub.

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"destroy_gil() is not called over multiple Py_Initialize() / Py_Finalize() calls","articleBody":"The following simple balanced calls to `Py_Initialize()` / `Py_FinalizeEx()` trigger an error when running under Microsoft's Application Verifier on Windows:\r\n\r\n```c\r\n  Py_Initialize();\r\n  Py_FinalizeEx();\r\n  Py_Initialize();\r\n  Py_FinalizeEx();\r\n```\r\n\r\nThe above sequence causes there to be two calls to `create_gil()` for the main GIL, without an intervening call to `destroy_gil()`: the mismatched use of `PyMUTEX_INIT()`/`PyMUTEX_FINI()` (`create_gil()` calls `PyMUTEX_INIT()` and `destroy_gil()` calls `PyMUTEX_FINI()`) translates into mismatched calls to Win32 APIs [`InitializeCriticalSection()`](https://learn.microsoft.com/en-us/windows/win32/api/synchapi/nf-synchapi-initializecriticalsection) and [`DeleteCriticalSection()`](https://learn.microsoft.com/en-us/windows/win32/api/synchapi/nf-synchapi-deletecriticalsection), which are then detected by Application Verifier.\r\n\r\n\\[Note, however, that this error is not specific to Windows and the GIL is being incorrectly re-initialised without a call to `PyMUTEX_FINI()` on all platforms.\\]\r\n\r\nThe first `Py_Initialize()` causes a call to `create_gil()` on `interp-\u003eceval.gil` for the main interpreter (`_PyRuntime._main_interpreter`), but as a result of bpo-9901, `finalize_interp_delete()` (as called from `Py_FinalizeEx()`) currently defers calling `_PyEval_FiniGIL()` (and thereby `destroy_gil()`) until the next `Py_Initialize()`:\r\n\r\n```c\r\nstatic void\r\nfinalize_interp_delete(PyInterpreterState *interp)\r\n{\r\n    /* Cleanup auto-thread-state */\r\n    _PyGILState_Fini(interp);\r\n\r\n    /* We can't call _PyEval_FiniGIL() here because destroying the GIL lock can\r\n       fail when it is being awaited by another running daemon thread (see\r\n       bpo-9901). Instead pycore_create_interpreter() destroys the previously\r\n       created GIL, which ensures that Py_Initialize / Py_FinalizeEx can be\r\n       called multiple times. */\r\n```\r\nhttps://github.com/python/cpython/blame/41aff464cef83d2655029ddd180a51110e8d7f8e/Python/pylifecycle.c#L1740\r\n\r\nUnfortunately, the second call `Py_Initialize()` doesn't call `destroy_gil()` before calling `create_gil()` a second time on the main interpreter's GIL, causing this error.\r\n\r\n@ericsnowcurrently's [comment on `init_interp_create_gil()`](https://github.com/python/cpython/blame/41aff464cef83d2655029ddd180a51110e8d7f8e/Python/pylifecycle.c#L594) ('`XXX This is broken with a per-interpreter GIL`'):\r\n\r\n```c\r\nstatic PyStatus\r\ninit_interp_create_gil(PyThreadState *tstate, int own_gil)\r\n{\r\n    PyStatus status;\r\n\r\n    /* finalize_interp_delete() comment explains why _PyEval_FiniGIL() is\r\n       only called here. */\r\n    // XXX This is broken with a per-interpreter GIL.\r\n    _PyEval_FiniGIL(tstate-\u003einterp);\r\n```\r\n\r\nnotes that the call to `_PyEval_FiniGIL()` in `init_interp_create_gil()` doesn't work with per-interpreter GIL, but it's worse than this as it's broken with just re-creating the main interpreter!\r\n\r\nThe reason for all this appears to be that the GIL is re-initialised by `_PyRuntime_Initialize()`, before `_PyEval_FiniGIL()` has a chance to get its hands on it. Prior to GH-104210 from @ericsnowcurrently landing yesterday (and on previous Python versions), `_PyEval_FiniGIL()` would detect that the GIL is reinitialised by a prior call to `_gil_initialize()` within `_PyRuntime_Initialize()`. However, now the main interpreter (`_PyRuntime._main_interpreter`) has a GIL pointer (`interp-\u003eceval.gil`) which is cleared when `_PyRuntimeState_Init()` resets the runtime to `_PyRuntimeState_INIT`:\r\n\r\n```c\r\n    if (runtime-\u003e_initialized) {\r\n        // Py_Initialize() must be running again.\r\n        // Reset to _PyRuntimeState_INIT.\r\n        memcpy(runtime, \u0026initial, sizeof(*runtime));\r\n    }\r\n```\r\n\r\nI have reproduced this with recent cpython commit [`bf89d4283a28dd00836f2c312a9255f543f93fc7`](https://github.com/python/cpython/commit/bf89d4283a28dd00836f2c312a9255f543f93fc7) and have attached a log of the callstacks \\([avrf-gil.txt](https://github.com/python/cpython/files/11431606/avrf-gil.txt)\\).\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-104325\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/adr26","@type":"Person","name":"adr26"},"datePublished":"2023-05-09T13:35:38.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":4},"url":"https://github.com/104324/cpython/issues/104324"}

route-pattern/:user_id/:repository/issues/:id(.:format)
route-controllerissues
route-actionshow
fetch-noncev2:2994eac4-cb1a-7c40-2f32-77dbe92f73de
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idBC6C:FD1F6:17BEB:1E755:696A58B2
html-safe-nonce92b48dc0d1a1bacb1acf0cde7c5d0c7cd90777c232a7497e0b1c93be84e65f8b
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCQzZDOkZEMUY2OjE3QkVCOjFFNzU1OjY5NkE1OEIyIiwidmlzaXRvcl9pZCI6IjE2MDQ0MjQ4MTk0NzE0NDAwNTAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac4e9a0bde47b6ef38a4d352c081e27884e3e0508c43efeefc387eddf3c96985f7
hovercard-subject-tagrepository:81598961
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///issues/show
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/python/cpython/issues/104324
twitter:imagehttps://opengraph.githubassets.com/056af25ef10a4e507d10d8e2a9ada4431b022725404b3970cd16e995046af629/python/cpython
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/056af25ef10a4e507d10d8e2a9ada4431b022725404b3970cd16e995046af629/python/cpython
og:image:altThe Python programming language. Contribute to python/cpython development by creating an account on GitHub.
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
None3f871c8e07f0ae1886fa8dac284166d28b09ad5bada6476fc10b674e489788ef
turbo-cache-controlno-cache
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
release63c426b30d262aba269ef14c40e3c817b384cd61
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/python/cpython/issues/104324#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F104324
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%2F104324
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%2Fissues%2Fshow&source=header-repo&source_repo=python%2Fcpython
Reloadhttps://github.com/python/cpython/issues/104324
Reloadhttps://github.com/python/cpython/issues/104324
Reloadhttps://github.com/python/cpython/issues/104324
python https://github.com/python
cpythonhttps://github.com/python/cpython
Please reload this pagehttps://github.com/python/cpython/issues/104324
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/104324
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/104324
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/104324
destroy_gil() is not called over multiple Py_Initialize() / Py_Finalize() callshttps://github.com/python/cpython/issues/104324#top
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/adr26
https://github.com/adr26
adr26https://github.com/adr26
on May 9, 2023https://github.com/python/cpython/issues/104324#issue-1702055343
InitializeCriticalSection()https://learn.microsoft.com/en-us/windows/win32/api/synchapi/nf-synchapi-initializecriticalsection
DeleteCriticalSection()https://learn.microsoft.com/en-us/windows/win32/api/synchapi/nf-synchapi-deletecriticalsection
bpo-9901https://bugs.python.org/issue?@action=redirect&bpo=9901
https://github.com/python/cpython/blame/41aff464cef83d2655029ddd180a51110e8d7f8e/Python/pylifecycle.c#L1740https://github.com/python/cpython/blame/41aff464cef83d2655029ddd180a51110e8d7f8e/Python/pylifecycle.c#L1740
@ericsnowcurrentlyhttps://github.com/ericsnowcurrently
comment on init_interp_create_gil()https://github.com/python/cpython/blame/41aff464cef83d2655029ddd180a51110e8d7f8e/Python/pylifecycle.c#L594
GH-104210https://github.com/python/cpython/pull/104210
@ericsnowcurrentlyhttps://github.com/ericsnowcurrently
bf89d4283a28dd00836f2c312a9255f543f93fc7https://github.com/python/cpython/commit/bf89d4283a28dd00836f2c312a9255f543f93fc7
avrf-gil.txthttps://github.com/python/cpython/files/11431606/avrf-gil.txt
gh-104324: Reinstate GIL cleanup during interpreter deletion. #104325https://github.com/python/cpython/pull/104325
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
Subinterpretershttps://github.com/orgs/python/projects/3
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.