René's URL Explorer Experiment


Title: Stop importing `threading` at interpreter shutdown by jseop-lim · Pull Request #9925 · RustPython/RustPython · GitHub

Open Graph Title: Stop importing `threading` at interpreter shutdown by jseop-lim · Pull Request #9925 · RustPython/RustPython

X Title: Stop importing `threading` at interpreter shutdown by jseop-lim · Pull Request #9925 · RustPython/RustPython

Description: Part of #9913 (item 17) This PR follows our AI policy Summary finalize_ex imports threading to call _shutdown(), so a program that never imported it runs the import machinery and threading._shutdown() on exit. A trace function still installed sees those frames, and sys.modules gains threading before the atexit callbacks run. CPython's wait_for_thread_shutdown looks the module up with PyImport_GetModule and returns when it was never imported. AS-IS $ rustpython -c "import atexit, sys; atexit.register(lambda: print('threading' in sys.modules))" True $ rustpython -c "import sys; sys.settrace(print)" ', line 1302, code _find_and_load> call None ', line 1283, code _resolve_parents> call None ... TO-BE $ rustpython -c "import atexit, sys; atexit.register(lambda: print('threading' in sys.modules))" False $ rustpython -c "import sys; sys.settrace(print)" (matching CPython 3.15.2) Changes In crates/vm/src/vm/interpreter.rs, finalize_ex takes threading from sys.modules and skips _shutdown() when it is absent. Extend extra_tests/snippets/stdlib_sys.py with a subprocess whose atexit callback prints whether threading is in sys.modules. Test plan Built and run on macOS aarch64 against upstream/main 7abccf0, using the CI feature set --no-default-features --features stdlib,importlib,stdio,encodings,sqlite,ssl-rustls-aws-lc,host_env,doc,ucd_3_2_0, plus threading, compared with CPython 3.15.2. The extended extra_tests/snippets/stdlib_sys.py fails on an unpatched build of that commit (AssertionError: True) and passes with the patch. CPython 3.15.2 prints False for the added subprocess; the snippet as a whole stops there earlier, at its sys.version_info[:3] == (3, 15, 0) assertion. A script that only calls sys.settrace(print) prints 408 traced frames at exit on the unpatched build and none with the patch. A non-daemon threading.Thread that outlives the main module is still joined at exit, and a thread started with _thread.start_new_thread is still not, as on the unpatched build and CPython. rustpython -m test test_threading test_atexit test_sys test_sys_settrace test_thread test_sys_setprofile: 874 run, 153 skipped, 1 failure, the same on the unpatched build. The failure is test_sys.test_stdlib_dir, which compares sys._stdlib_dir with the Lib directory I pointed RUSTPYTHONPATH at. cargo fmt --check clean, cargo clippy -p rustpython-vm -p rustpython-stdlib --all-targets adds no warning, and the pre-commit hooks other than cspell and prettier pass on both changed files. I used Claude Code (claude-fable-5-2) to draft the analysis, the patch and this description; Claude Code ran the commands above; I reviewed the diff and their output. Summary by CodeRabbit Bug Fixes Interpreter shutdown no longer loads the threading module if it was not already loaded. When available, its shutdown hook still runs, and any errors continue to be reported as unraisable.

Open Graph Description: Part of #9913 (item 17) This PR follows our AI policy Summary finalize_ex imports threading to call _shutdown(), so a program that never imported it runs the import machinery and threading._shutd...

X Description: Part of #9913 (item 17) This PR follows our AI policy Summary finalize_ex imports threading to call _shutdown(), so a program that never imported it runs the import machinery and threading._shutd...

Opengraph URL: https://github.com/RustPython/RustPython/pull/9925

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:0d8be625-2f43-7f09-184c-2729c3cbaca5
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-id9C3C:842EC:2D855A2:3CBBEE0:6B01D7FC
html-safe-nonceb30b11ab39451fb76d8c5f233007b3ad3db259ce3457805a292036f8b4356e58
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5QzNDOjg0MkVDOjJEODU1QTI6M0NCQkVFMDo2QjAxRDdGQyIsInZpc2l0b3JfaWQiOiIzMjQyNzM3NjAzNDc2MzE0MTA4IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmac5fce37795cd4b25a72935f1a5fa2942eaebaabaa9005d1d039aa1d507f1e6679
hovercard-subject-tagpull_request:5361510935
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/RustPython/RustPython/pull/9925/files
twitter:imagehttps://avatars.githubusercontent.com/u/86508420?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/86508420?s=400&v=4
og:image:altPart of #9913 (item 17) This PR follows our AI policy Summary finalize_ex imports threading to call _shutdown(), so a program that never imported it runs the import machinery and threading._shutd...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
Nonecc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c
turbo-cache-controlno-preview
diff-viewunified
go-importgithub.com/RustPython/RustPython git https://github.com/RustPython/RustPython.git
octolytics-dimension-user_id39710557
octolytics-dimension-user_loginRustPython
octolytics-dimension-repository_id135201145
octolytics-dimension-repository_nwoRustPython/RustPython
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id135201145
octolytics-dimension-repository_network_root_nwoRustPython/RustPython
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
release8c77c9e8439031ad54c75a250694842892f693e1
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/RustPython/RustPython/pull/9925/files#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2FRustPython%2FRustPython%2Fpull%2F9925%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%2FRustPython%2FRustPython%2Fpull%2F9925%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=RustPython%2FRustPython
Reloadhttps://github.com/RustPython/RustPython/pull/9925/files
Reloadhttps://github.com/RustPython/RustPython/pull/9925/files
Reloadhttps://github.com/RustPython/RustPython/pull/9925/files
RustPythonhttps://github.com/RustPython
RustPythonhttps://github.com/RustPython/RustPython
Codehttps://github.com/RustPython/RustPython
Issues195 (195)https://github.com/RustPython/RustPython/issues
Pull requests132 (132)https://github.com/RustPython/RustPython/pulls
Discussionshttps://github.com/RustPython/RustPython/discussions
Actionshttps://github.com/RustPython/RustPython/actions
Projectshttps://github.com/RustPython/RustPython/projects
Wikihttps://github.com/RustPython/RustPython/wiki
Security and qualityhttps://github.com/RustPython/RustPython/security
Insightshttps://github.com/RustPython/RustPython/insights
Sign up for GitHub https://github.com/signup?return_to=%2FRustPython%2FRustPython%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2FRustPython%2FRustPython%2Fissues%2Fnew%2Fchoose
jseop-limhttps://github.com/jseop-lim
RustPython:mainhttps://github.com/RustPython/RustPython/tree/main
jseop-lim:fix/shutdown-threading-importhttps://github.com/jseop-lim/RustPython/tree/fix/shutdown-threading-import
Conversation 6 https://github.com/RustPython/RustPython/pull/9925
Commits 2 https://github.com/RustPython/RustPython/pull/9925/commits
Checks 27 https://github.com/RustPython/RustPython/pull/9925/checks
Files changed 2 https://github.com/RustPython/RustPython/pull/9925/files
Stop importing threading at interpreter shutdown https://github.com/RustPython/RustPython/pull/9925/files#top
Show all changes 2 commits https://github.com/RustPython/RustPython/pull/9925/files
3eadb6e Stop importing `threading` at interpreter shutdown jseop-lim Nov 17, 2026 https://github.com/RustPython/RustPython/pull/9925/commits/3eadb6ebc0c2ca3cd7326df619e3e3a45cb7a05d
0b78e81 Merge branch 'main' into fix/shutdown-threading-import youknowone Nov 21, 2026 https://github.com/RustPython/RustPython/pull/9925/commits/0b78e816cc749b9c24f90d7b9031f49a75fbcf97
Clear filters https://github.com/RustPython/RustPython/pull/9925/files
Please reload this pagehttps://github.com/RustPython/RustPython/pull/9925/files
Please reload this pagehttps://github.com/RustPython/RustPython/pull/9925/files
interpreter.rs https://github.com/RustPython/RustPython/pull/9925/files#diff-2361f366cc46771907dbd3b09eb8b9c839e7f059710345f2265c1753862a1b20
stdlib_sys.py https://github.com/RustPython/RustPython/pull/9925/files#diff-fd9bcddc1221ad047d9d5280805f530b9186fcc9e293c80fbc1f4a69f99bc976
crates/vm/src/vm/interpreter.rshttps://github.com/RustPython/RustPython/pull/9925/files#diff-2361f366cc46771907dbd3b09eb8b9c839e7f059710345f2265c1753862a1b20
View file https://github.com/RustPython/RustPython/blob/0b78e816cc749b9c24f90d7b9031f49a75fbcf97/crates/vm/src/vm/interpreter.rs
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/RustPython/RustPython/pull/9925/{{ revealButtonHref }}
https://github.com/RustPython/RustPython/pull/9925/files#diff-2361f366cc46771907dbd3b09eb8b9c839e7f059710345f2265c1753862a1b20
chatgpt-codex-connectorhttps://github.com/apps/chatgpt-codex-connector
Nov 18, 2026https://github.com/RustPython/RustPython/pull/9925/files#r4612912707
Learn morehttps://docs.github.com/articles/managing-disruptive-comments/#hiding-a-comment
https://camo.githubusercontent.com/0854bfc38139c0d2b58a9d5d71f5ad92840cf0c17144621e462b474041793354/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f50322d79656c6c6f773f7374796c653d666c6174
Please reload this pagehttps://github.com/RustPython/RustPython/pull/9925/files
https://github.com/RustPython/RustPython/pull/9925/files#diff-2361f366cc46771907dbd3b09eb8b9c839e7f059710345f2265c1753862a1b20
extra_tests/snippets/stdlib_sys.pyhttps://github.com/RustPython/RustPython/pull/9925/files#diff-fd9bcddc1221ad047d9d5280805f530b9186fcc9e293c80fbc1f4a69f99bc976
View file https://github.com/RustPython/RustPython/blob/0b78e816cc749b9c24f90d7b9031f49a75fbcf97/extra_tests/snippets/stdlib_sys.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/RustPython/RustPython/pull/9925/{{ revealButtonHref }}
https://github.com/RustPython/RustPython/pull/9925/files#diff-fd9bcddc1221ad047d9d5280805f530b9186fcc9e293c80fbc1f4a69f99bc976
coderabbitaihttps://github.com/apps/coderabbitai
Nov 21, 2026https://github.com/RustPython/RustPython/pull/9925/files#r4653401826
Learn morehttps://docs.github.com/articles/managing-disruptive-comments/#hiding-a-comment
Please reload this pagehttps://github.com/RustPython/RustPython/pull/9925/files
https://github.com/RustPython/RustPython/actions/runs/44919371614/job/136891861608?pr=9925
https://github.com/RustPython/RustPython/pull/9925/files#diff-fd9bcddc1221ad047d9d5280805f530b9186fcc9e293c80fbc1f4a69f99bc976
Please reload this pagehttps://github.com/RustPython/RustPython/pull/9925/files
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.