junyixie <xie.ju...@outlook.com> added the comment:
> Which API should be used in C extensions to be "subinterpreter-safe"? ?> > Currently, Py_None is a singleton shared by multiple interpreters. > > > > Should suddenly all C extensions use a new Py_GetNone() function which > > returns the per-interpreter singleton? If yes, that's basically what my > PR > 18301 does: > #define Py_None Py_GetNone() after read you [WIP] bpo-39511: Add Py_GetNone() and Py_GetNoneRef() functions #18301. Actually, interp->none shared _Py_NoneStruct variable. when two interperter modify interp->none refcount,will modify _Py_NoneStruct variable. > the CPU cacheline of common singletons like None, True and False can quickly > become a performance bottleneck. even if add Py_INCREF(none);. In the scenario of parallel interpreter, will also have thread safety issues. > PyStatus > _Py_InitSingletons(PyThreadState *tstate) > { > PyObject *none = &_Py_NoneStruct; > Py_INCREF(none); > tstate->interp->none = none; > return _PyStatus_OK(); > } ---------- nosy: +JunyiXie -Mark.Shannon, corona10, eric.snow, jeremy.kloth, jkloth, larry, maciej.szulik, nanjekyejoannah, ncoghlan, phsilva, rhettinger, shihai1991, steve.dower _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue39511> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com