Title: (Mostly) Stop Special-casing the Main Interpreter · Issue #109857 · python/cpython · GitHub
Open Graph Title: (Mostly) Stop Special-casing the Main Interpreter · Issue #109857 · python/cpython
X Title: (Mostly) Stop Special-casing the Main Interpreter · Issue #109857 · python/cpython
Description: Feature or enhancement We make a bunch of accommodations for the "main" (initial) interpreter, especially during initialization and finalization. This adds complexity to the runtime. We should consider making the main interpreter (mostly...
Open Graph Description: Feature or enhancement We make a bunch of accommodations for the "main" (initial) interpreter, especially during initialization and finalization. This adds complexity to the runtime. We should cons...
X Description: Feature or enhancement We make a bunch of accommodations for the "main" (initial) interpreter, especially during initialization and finalization. This adds complexity to the runtime. We s...
Opengraph URL: https://github.com/python/cpython/issues/109857
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"(Mostly) Stop Special-casing the Main Interpreter","articleBody":"# Feature or enhancement\n\nWe make a bunch of accommodations for the \"main\" (initial) interpreter, especially during initialization and finalization. This adds complexity to the runtime. We should consider making the main interpreter (mostly) *not* special. At most we need to specifically special-case relative to the main thread.\n\nThe main thread of a Python program uses the initial thread state of the main interpreter. That thread is special for the following reasons, at least for the Python executable (and for some embedding cases):\n\n* where the main code of the app executes\n* where the REPL runs\n* where signal handlers run\n* where the main (initial) interpreter is always created\n* (usually) where runtime finalization happens\n\nThus the initial thread state of the main interpreter plays a critical role. The code reflects this, especially in Python/pylifecycle.c. However, a lot of the special treatment of the main interpreter is unnecessary. [^1]\n\n[^1]: FYI, we also optimize the code somewhat using the fact that the initial thread state of the main interpreter is likely to be the active one (e.g. that thread state and interpreter state are statically allocated and initialized). However, I'm not sure we need to change much about this.\n\nThe main interpreter is the one created during runtime initialization and used during initialization. This is relevant for any non-immortal, non-static objects that we store on `_PyRuntimeState`, which we should strenuously avoid doing anyway. It is likely also relevant for embedders.\n\nThere are also a couple of places where the \"main\" interpreter needs to be factored in (which we currently isn't), but doesn't necessarily need to be addressed with this issue:\n\n* runtime finalization should happen in the main thread, with the main interpreter?\n* `os.fork()` should update the main thread state and the main interpreter (or only be allowed in the main thread of the main interpreter)?\n\nCC @markshannon, @vstinner, @ncoghlan, @zooba","author":{"url":"https://github.com/ericsnowcurrently","@type":"Person","name":"ericsnowcurrently"},"datePublished":"2023-09-25T16:39:30.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":6},"url":"https://github.com/109857/cpython/issues/109857"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:dc096efc-c167-3335-4127-4692533489cf |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C9E4:30B448:10A95FB:1758E0A:696A4287 |
| html-safe-nonce | 15d04f44e5586e756e5de0bf43fb1829f1514e2e3f241a3b89529ca07590eff2 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDOUU0OjMwQjQ0ODoxMEE5NUZCOjE3NThFMEE6Njk2QTQyODciLCJ2aXNpdG9yX2lkIjoiOTAxODg3NjkyODk5MDAwMzg0NyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | a1ed19e77e97e84d9be30ef9c282b8b3202fbfbb992f32c5e925621a9f47a79a |
| hovercard-subject-tag | issue:1911901784 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/109857/issue_layout |
| twitter:image | https://opengraph.githubassets.com/afdc1cec7513bfc32fdbaac9bc2a7a12a26e36be74c65a26f5b7a09c576aca10/python/cpython/issues/109857 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/afdc1cec7513bfc32fdbaac9bc2a7a12a26e36be74c65a26f5b7a09c576aca10/python/cpython/issues/109857 |
| og:image:alt | Feature or enhancement We make a bunch of accommodations for the "main" (initial) interpreter, especially during initialization and finalization. This adds complexity to the runtime. We should cons... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | ericsnowcurrently |
| hostname | github.com |
| expected-hostname | github.com |
| None | 3f871c8e07f0ae1886fa8dac284166d28b09ad5bada6476fc10b674e489788ef |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 63c426b30d262aba269ef14c40e3c817b384cd61 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width