[issue40533] Subinterpreters: don't share Python objects between interpreters

STINNER Victor report at bugs.python.org
Wed May 6 11:11:35 EDT 2020


New submission from STINNER Victor <vstinner at python.org>:

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.

----------
components: Interpreter Core
messages: 368262
nosy: vstinner
priority: normal
severity: normal
status: open
title: Subinterpreters: don't share Python objects between interpreters
versions: Python 3.9

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue40533>
_______________________________________


More information about the Python-bugs-list mailing list