Skip to content

Conversation

@vstinner
Copy link
Member

@vstinnervstinner commented May 6, 2020

When Python is built with experimental isolated interpreters, declare
PyObject.ob_refcnt and _dictkeysobject.dk_refcnt as atomic variables.

Temporary workaround until subinterpreters stop sharing Python
objects.

https://bugs.python.org/issue40533

When Python is built with experimental isolated interpreters, declare PyObject.ob_refcnt and _dictkeysobject.dk_refcnt as atomic variables. Temporary workaround until subinterpreters stop sharing Python objects.
@vstinner
Copy link
MemberAuthor

@aeros
Copy link
Contributor

aeros commented May 6, 2020

Based on the discussion at https://mail.python.org/archives/list/python-committers@python.org/thread/2WHQBHFK7UQ7OYAJV5S2QCINODVVKGJY/#2WHQBHFK7UQ7OYAJV5S2QCINODVVKGJY, I think we should leave a DO-NOT-MERGE label until the 3.9 branch is created.

@vstinnervstinner marked this pull request as draft May 6, 2020 22:34
@vstinner
Copy link
MemberAuthor

Based on the discussion at https://mail.python.org/archives/list/python-committers@python.org/thread/2WHQBHFK7UQ7OYAJV5S2QCINODVVKGJY/#2WHQBHFK7UQ7OYAJV5S2QCINODVVKGJY, I think we should leave a DO-NOT-MERGE label until the 3.9 branch is created.

Right, thanks. I converted this PR into a draft to ensure that nobody merges it by mistake.

@vstinnervstinner changed the title bpo-40533: Make PyObject.ob_refcnt atomic in subinterpreters[WIP] bpo-40533: Make PyObject.ob_refcnt atomic in subinterpretersMay 6, 2020
Comment on lines +107 to +111
#ifdefEXPERIMENTAL_ISOLATED_SUBINTERPRETERS
/* bpo-40533: Use an atomic variable for PyObject.ob_refcnt, to ensure that
Py_INCREF() and Py_DECREF() are safe when called in parallel, until
subinterpreters stop sharing Python objects. */
_Atomic Py_ssize_tob_refcnt;
Copy link
Contributor

@aerosaerosMay 6, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps this is somewhat emphasized by the "experimental" part, but could we possibly make it a bit more crystal clear that this is only a temporary stopgap measure? I personally find that "until subinterpreters stop sharing Python objects" could be interpreted as a near indefinite amount of time; I'm not confident that most readers will go over the full context in the bpo issue and related discussions.

Normally, this wouldn't be a huge concern, but I think object.h is likely one of the most public-facing header files in CPython, so it seems important to communicate this as clearly as possible.

@vstinner
Copy link
MemberAuthor

The current plan is to not share any object between two interpreters, so this PR is not needed. I close it.

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@vstinner@aeros@the-knights-who-say-ni@bedevere-bot