Title: [subinterpreters] Static types incorrectly share some objects between interpreters · Issue #94673 · python/cpython · GitHub
Open Graph Title: [subinterpreters] Static types incorrectly share some objects between interpreters · Issue #94673 · python/cpython
X Title: [subinterpreters] Static types incorrectly share some objects between interpreters · Issue #94673 · python/cpython
Description: While static types (PyTypeObject values) don't themselves ever change (once PyType_Ready() has run), they do hold mutable data. This means they cannot be safely shared between multiple interpreters without a common GIL (and without state...
Open Graph Description: While static types (PyTypeObject values) don't themselves ever change (once PyType_Ready() has run), they do hold mutable data. This means they cannot be safely shared between multiple interpreters...
X Description: While static types (PyTypeObject values) don't themselves ever change (once PyType_Ready() has run), they do hold mutable data. This means they cannot be safely shared between multiple interpre...
Opengraph URL: https://github.com/python/cpython/issues/94673
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[subinterpreters] Static types incorrectly share some objects between interpreters","articleBody":"While static types (`PyTypeObject` values) don't themselves ever change (once `PyType_Ready()` has run), they do hold mutable data. This means they cannot be safely shared between multiple interpreters without a common GIL (and without state leaking between).\r\n\r\nMutable data:\r\n\r\n* the object header (e.g. refcount), as with all objects\r\n* otherwise immutable objects:\r\n * ob_type (`__class__`)\r\n * tp_base (`__base__`) - set by `PyType_Ready()` if not set\r\n * tp_bases (`__bases__`) - always set by `PyType_Ready()`\r\n * tp_mro (`__mro__`) - always set by `PyType_Ready()`\r\n * tp_dict (`__dict__`) - set by `PyType_Ready()` if not set\r\n* mutable containers:\r\n * tp_subclasses (`__subclasses__`)\r\n * tp_weaklist\r\n\r\n(See https://docs.python.org/3/c-api/typeobj.html#tp-slots.)\r\n(Note that `tp_cache` is no longer used.)\r\n \r\nFor the object header, if PEP 683 (immortal objects) is accepted then we can make static types immortal.\r\n\r\nFor the otherwise immutable objects, we can make sure each is immortal and then we're good. Even `tp_dict` is fine since it gets hidden behind `types.MappingProxyType`. We'd also need to either make sure each contained item is immortal.\r\n\r\nFor `tp_subclasses` we will need a per-interpreter copy, and do the proper lookup in the `__subclasses__` getter. The cache could be stored on `PyInterpreterState` or even as a dict in `tp_subclasses`.\r\n\r\nFor `tp_weaklist` it's a similar story as for `tp_subclasses`. Note that `tp_weaklist` isn't very important for static types since they are never deallocated.\r\n\r\n(The above is also discussed in [PEP 684](https://peps.python.org/pep-0684/#global-objects).)\r\n\r\nCC @kumaraditya303\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-102663\n* gh-103912\n* gh-103940\n* gh-103961\n* gh-104072\n* gh-104074\n* gh-105465\n* gh-105471\n* gh-117761\n* gh-117980\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/ericsnowcurrently","@type":"Person","name":"ericsnowcurrently"},"datePublished":"2022-07-07T22:45:31.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":15},"url":"https://github.com/94673/cpython/issues/94673"}
| 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:89becb1e-190b-f10a-dfad-b0d6ac0b8c6f |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D7E8:2C594F:5C1C74:7FE042:69694C95 |
| html-safe-nonce | c48f9dfb809ad610175d77f04c408bf621915001f1318a79c346d283737f4898 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEN0U4OjJDNTk0Rjo1QzFDNzQ6N0ZFMDQyOjY5Njk0Qzk1IiwidmlzaXRvcl9pZCI6IjcwODA3Njg1MjE0NDM1NjA1OTciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 827a3d9ce913b950855233e0e7a2648ecd9b38757cd7a8d5365673364ffadc26 |
| hovercard-subject-tag | issue:1298212994 |
| 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/94673/issue_layout |
| twitter:image | https://opengraph.githubassets.com/3c0c4845e23f147de52f80f28bc992640a1ac1172e5d5fc11d069b79180b03a9/python/cpython/issues/94673 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/3c0c4845e23f147de52f80f28bc992640a1ac1172e5d5fc11d069b79180b03a9/python/cpython/issues/94673 |
| og:image:alt | While static types (PyTypeObject values) don't themselves ever change (once PyType_Ready() has run), they do hold mutable data. This means they cannot be safely shared between multiple interpreters... |
| 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 | 54182691a21263b584d2e600b758e081b0ff1d10ffc0d2eefa51cf754b43b51d |
| 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 | d69ac0477df0f87da03b8b06cebd187012d7a930 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width