Repository navigation
[subinterpreters] Don't share Python objects between interpreters #84713
Description
Activity
To get one GIL per interpreter (bpo-40512), either PyObject.ob_refcnt member must become an atomic variable, or subinterpreters must not share any object.
Right now, subinterpreters share Python objects. For example, PyModule_Type is declared statically and so shared by all interpreters and so PyModule_Type.tp_mro tuple is accessed in parallel by multiple interpreters. If PyObject.ob_refcnt is not atomic, Py_INCREF() and Py_DECREF() are unsafe and tp_mro tuple can be destroyed whereas it is still used.
I propose to make PyObject.ob_refcnt atomic for now, when Python is built with EXPERIMENTAL_ISOLATED_SUBINTERPRETERS macro defined. It's a temporary workaround until subinterpreters stop sharing objects.
- addedinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)3.9 (EOL)end of lifeend of life
on May 6, 2020 Yep, before per-interpreter GIL is official we must get to the point where *no* PyObject objects are shared.
Making PyObject.ob_refcnt atomic until then (only as part of the experiment) should be fine.
Yep, before per-interpreter GIL is official we must get to the point where *no* PyObject objects are shared.
I would like to add: "no PyObject objects are shared in the stdlib" ;-)
- added and removedinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)
on May 15, 2020 - changed the title
[-]Subinterpreters: don't share Python objects between interpreters[/-][+][subinterpreters] Don't share Python objects between interpreters[/+]on May 15, 2020 - added and removedinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)
on May 15, 2020 - changed the title
[-]Subinterpreters: don't share Python objects between interpreters[/-][+][subinterpreters] Don't share Python objects between interpreters[/+]on May 15, 2020 For example, PyModule_Type is declared statically and so shared by all interpreters and so PyModule_Type.tp_mro tuple is accessed in parallel by multiple interpreters.
Another example of this issue are parallel Py_INCREF/Py_DECREF calls on the tp_bases member of a type.
To get one GIL per interpreter (bpo-40512), either PyObject.ob_refcnt member must become an atomic variable, or subinterpreters must not share any object.
The current plan is to not share any object between two interpreters, so this PR is not needed. I close my PR 19958 which marked PyObject.ob_refcnt as atomic.
Until all Python stdlib C extensions and all third-party C extensions will be modified to no longer use and define static types and will stop shared Python objects between two interpreters, we can no longer micro-optimize the comparison of two interned strings by only comparing their memory addresse. See bpo-46006.
Sharing objects between multiple interpreters can cause complex bugs leading to crashes: https://bugs.python.org/issue46070#msg410493 For this specific bug, I wrote a workaround (GH-30577).
I don't have the bandwidth to work on this issue, so I just close it.
Metadata
Metadata
Assignees
Labels
Projects
- StatusShow more project fieldsDone
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields: