René's URL Explorer Experiment


Title: Fix Refleak in test_import · Issue #102251 · python/cpython · GitHub

Open Graph Title: Fix Refleak in test_import · Issue #102251 · python/cpython

X Title: Fix Refleak in test_import · Issue #102251 · python/cpython

Description: Commit 096d009 (for gh-101758) resulted in refleak failures. It's unclear if the leak is new or if the test simply exposed it. In 984f8ab, I skipped the leaking tests until we can fix the leak. UPDATE: I've updates the tests to only skip...

Open Graph Description: Commit 096d009 (for gh-101758) resulted in refleak failures. It's unclear if the leak is new or if the test simply exposed it. In 984f8ab, I skipped the leaking tests until we can fix the leak. UPD...

X Description: Commit 096d009 (for gh-101758) resulted in refleak failures. It's unclear if the leak is new or if the test simply exposed it. In 984f8ab, I skipped the leaking tests until we can fix the leak....

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Fix Refleak in test_import","articleBody":"Commit 096d0097a09e (for gh-101758) resulted in refleak failures.  It's unclear if the leak is new or if the test simply exposed it.  In 984f8ab018f847fe8d66768af962f69ec0e81849, I skipped the leaking tests until we can fix the leak.\r\n\r\nUPDATE:  I've updates the tests to only skip when checking for refleaks.  I've also added a few more tests.\r\n\r\n----\r\n\r\n### Context\r\n\r\n\u003cdetails\u003e\r\n\u003csummary\u003e(expand)\u003c/summary\u003e\r\n\r\n\u003cBR/\u003e\r\n(Also see gh-101758.)\r\n\u003cBR/\u003e\u003cBR/\u003e\r\n\r\nLoading an extension module involves meaningfully different code paths depending on the content of the `PyModuleDef`.  There's the difference between legacy (single-phase-init, PEP 3121) and modern (multi-phase-init, PEP 489) modules.  For single-phase init, there are those that support being loaded more than once (`m_size` \u003e= 0) and those that can't (`m_size` == -1).  I've added several long comments in import.c explaining about single-phase init modules in detail.  I also added some tests to verify the behavior of the single-phase-init cases more thoroughly.  Those are the leaking tests.\r\n\r\nRelevant state:\r\n\r\n* `PyModuleDef.m_size` - the size of the module's per-interpreter state (`PyModuleObject.md_state`)\r\n   * single-phase init and multi-phase init modules can have a value of 0 or greater\r\n   * such modules must not have any process-global state\r\n   * only single-phase init modules can have a value of -1, which means the module does not support being loaded more than once\r\n   * such modules may have process-global state\r\n* `PyModuleDef.m_base.m_index` - the index into `PyInterpreterState.imports.modules_by_index`  (same index used for every interpreter)\r\n   * set by `PyModuleDef_Init()`  (e.g. when the module is created)\r\n* `PyModuleDef.m_base.m_copy` - a copy of the `__dict__` of the last time a module was *loaded* using this def  (only single-phase init where `m_size` is -1)\r\n   * set exclusively by `fix_up_extension()`\r\n   * used exclusively by `import_find_extension()`\r\n   * cleared by (replaced in) `fix_up_extension()` if `m_copy` was already set  (e.g. multiple interpreters, multiple modules in same file using same def)\r\n   * cleared by `_PyImport_ClearModulesByIndex()` during interpreter finalization\r\n* `_PyRuntime.imports.extensions` - a dict mapping `(filename, name)` to `PyModuleDef`\r\n   * entry set exclusively by `fix_up_extension()`  (only for single-phase init modules)\r\n   * entry used exclusively by `import_find_extension()`\r\n   * entry cleared by `_PyImport_Fini()` at runtime finalization\r\n* `interp-\u003eimports.modules_by_index` - a list of single-phase-init modules loaded in this interpreter; lookups (e.g. `PyState_FindModule()`) use `PyModuleDef.m_base.m_index`\r\n   * entry set normally only by `fix_up_extension()` and `import_find_extension()`  (only single-phase init modules)\r\n   * (entry also set by `PyState_AddModule()`)\r\n   * used exclusively by `PyState_FindModule()`\r\n   * entry cleared normally by `_PyImport_ClearModulesByIndex()` during interpreter finalization\r\n   * (entry also cleared by `PyState_RemoveModule()`)\r\n\r\nCode path when loading a single-phase-init module for the first time (in import.c, unless otherwise noted):\r\n\r\n* `imp.load_dynamic()`\r\n   * `importlib._boostrap._load()`  (using a spec with `ExtensionFileLoader`)\r\n      * `ExtensionFileLoader.create_module()`  (in _boostrap_external.py)\r\n         * `_imp.create_dynamic()`  (`_imp_create_dynamic_impl()`)\r\n            * `import_find_extension()`  (not found in `_PyRuntime.imports.extensions`)\r\n            * `_PyImport_LoadDynamicModuleWithSpec()`  (importdl.c)\r\n               * `_PyImport_FindSharedFuncptr()`\r\n               * `\u003cmodule init func from loaded binary\u003e()`\r\n                  * sets process-global state  (only where `m_size == -1`)\r\n                  * `PyModule_Create()`\r\n                  * populates per-interpreter module state  (only where `m_size \u003e 0`)\r\n                  * sets module attrs  (on `__dict__`)\r\n               * sets `def-\u003em_base.m_init`  (only needed for single-phase-init where `m_size \u003e=0`)\r\n               * `_PyImport_FixupExtensionObject()`\r\n                  * sets `sys.modules[spec.name]`\r\n                  * `fix_up_extension()`\r\n                     * set `interp-\u003eimports.modules_by_index[def-\u003em_base.m_index]`\r\n                     * clear `def-\u003em_base.m_copy`  (only if set and only if `m_size == -1`)\r\n                     * set `def-\u003em_base.m_copy` to a copy of the module's `__dict__`  (only if `m_size == -1`)\r\n                     * set `_PyRuntime.imports.extensions[(filename, name)]`\r\n      * sets missing module attrs (e.g. `__file__`)\r\n\r\nDuring testing we use a helper to erase (nearly) any evidence of the module having been imported before.  That means clearing the state described above.\r\n\r\nHere's the code path:\r\n\r\n* `_testinternalcapi.clear_extension()`  (Modules/_testinternalcapi.c)\r\n   * `_PyImport_ClearExtension()`\r\n      * `clear_singlephase_extension()`\r\n         * (only if there's a `_PyRuntime.imports.extensions` entry)\r\n            * clear the module def's `m_copy`\r\n            * replace the `interp-\u003eimports.modules_by_index` entry with `Py_None`\r\n            * delete the `_PyRuntime.imports.extensions` entry\r\n\r\n\u003c/details\u003e\r\n\r\n\u003c!-- gh-linked-prs --\u003e\r\n### Linked PRs\r\n* gh-102254\r\n* gh-104796\n* gh-105082\n* gh-105083\n* gh-105085\n* gh-105170\n* gh-106013\n* gh-109540\n\u003c!-- /gh-linked-prs --\u003e\r\n","author":{"url":"https://github.com/ericsnowcurrently","@type":"Person","name":"ericsnowcurrently"},"datePublished":"2023-02-25T18:19:13.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":9},"url":"https://github.com/102251/cpython/issues/102251"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:859e7cb3-31c8-bf3e-c5ca-fd48d353258b
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idCE20:495C0:7B9461:A5218C:69697953
html-safe-nonced4d3fcaf701dea54b548a1367702cd67d8923007168c47e516a44960f65415a6
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDRTIwOjQ5NUMwOjdCOTQ2MTpBNTIxOEM6Njk2OTc5NTMiLCJ2aXNpdG9yX2lkIjoiMTA3MjA4NjY4MjgxMTU5NTA5MSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac031e8e849a9d606538ee27234c5cdf104132616906fd777a7cc505e700049ce0
hovercard-subject-tagissue:1599789283
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/102251/issue_layout
twitter:imagehttps://opengraph.githubassets.com/e8bb5478423820fea89829726855ca3df3f8fe5ed1e3ebacf792edc8f3a79ee8/python/cpython/issues/102251
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/e8bb5478423820fea89829726855ca3df3f8fe5ed1e3ebacf792edc8f3a79ee8/python/cpython/issues/102251
og:image:altCommit 096d009 (for gh-101758) resulted in refleak failures. It's unclear if the leak is new or if the test simply exposed it. In 984f8ab, I skipped the leaking tests until we can fix the leak. UPD...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameericsnowcurrently
hostnamegithub.com
expected-hostnamegithub.com
Nonec6f193beb8ff08443adc07685d75302ab8aaf0a135f6e251c3ff3112c8deb881
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
release212e3e3d3298bf5b313830edfd2399e869f7ea76
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/python/cpython/issues/102251#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F102251
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%2F102251
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/102251
Reloadhttps://github.com/python/cpython/issues/102251
Reloadhttps://github.com/python/cpython/issues/102251
python https://github.com/python
cpythonhttps://github.com/python/cpython
Please reload this pagehttps://github.com/python/cpython/issues/102251
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/102251
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/102251
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/102251
Fix Refleak in test_importhttps://github.com/python/cpython/issues/102251#top
3.12only security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.12%22
extension-modulesC modules in the Modules dirhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22extension-modules%22
type-featureA feature request or enhancementhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-feature%22
https://github.com/ericsnowcurrently
https://github.com/ericsnowcurrently
ericsnowcurrentlyhttps://github.com/ericsnowcurrently
on Feb 25, 2023https://github.com/python/cpython/issues/102251#issue-1599789283
096d009https://github.com/python/cpython/commit/096d0097a09e439a4564531b297a998e5d74c9b5
gh-101758https://github.com/python/cpython/issues/101758
984f8abhttps://github.com/python/cpython/commit/984f8ab018f847fe8d66768af962f69ec0e81849
gh-101758https://github.com/python/cpython/issues/101758
gh-102251: Updates to test_imp Toward Fixing Some Refleaks #102254https://github.com/python/cpython/pull/102254
gh-102251: add missing cleanups for test_import #104796https://github.com/python/cpython/pull/104796
gh-102251: Fix reference leak in _testsinglephase initialization #105082https://github.com/python/cpython/pull/105082
[3.12] gh-102251: Fix reference leak in _testsinglephase initialization (GH-105082) #105083https://github.com/python/cpython/pull/105083
gh-102251: Explicitly free state for test modules with state in test_import #105085https://github.com/python/cpython/pull/105085
[3.12] gh-102251: Explicitly free state for test modules with state in test_import (GH-105085) #105170https://github.com/python/cpython/pull/105170
gh-102251: Disable non-rerunnable test in test_import #106013https://github.com/python/cpython/pull/106013
[3.12] gh-102251: Disable non-rerunnable test in test_import (GH-106013) #109540https://github.com/python/cpython/pull/109540
3.12only security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.12%22
extension-modulesC modules in the Modules dirhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22extension-modules%22
type-featureA feature request or enhancementhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-feature%22
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.