bpo-38266: Revert bpo-37878: Make PyThreadState_DeleteCurrent() Internal#16558
bpo-38266: Revert bpo-37878: Make PyThreadState_DeleteCurrent() Internal#16558vstinner merged 6 commits intopython:masterfrom
Conversation
| Destroy the current thread state and release the global interpreter lock. | ||
| Like :c:func:`PyThreadState_Delete`, the global interpreter lock need not | ||
| be held. The thread state must have been reset with a previous call | ||
| to :c:func:`PyThreadState_Clear`. |
There was a problem hiding this comment.
If we start to "expose" this function, would it be possible to be less strict and call PyThreadState_Clear() in PyThreadState_DeleteCurrent()? It sems like calling PyThreadState_Clear() twice is safe.
There was a problem hiding this comment.
I marked https://bugs.python.org/issue38266 as a release blocker, so the PyThreadState_Clear() question can definitely wait after 3.8.0: we can even revisit this in Python 3.9. Let's stick to adding back the function unmodified.
| PyAPI_FUNC(void) _PyErr_Display(PyObject *file, PyObject *exception, | ||
| PyObject *value, PyObject *tb); | ||
|
|
||
| PyAPI_FUNC(void) _PyThreadState_DeleteCurrent(_PyRuntimeState *runtime); |
There was a problem hiding this comment.
I don't understand why do you remove this definition: it's still used, no?
There was a problem hiding this comment.
I am now exposing PyThreadState_DeleteCurrent() instead of the internal _PyThreadState_DeleteCurrent() I thought. what are you thinking?
There was a problem hiding this comment.
_PyThreadState_DeleteCurrent() has to stay, it's part of https://pythoncapi.readthedocs.io/runtime.html effort to avoid global variables.
Include/cpython/pystate.h
Outdated
| PyAPI_FUNC(PyInterpreterState *) PyInterpreterState_Next(PyInterpreterState *); | ||
| PyAPI_FUNC(PyThreadState *) PyInterpreterState_ThreadHead(PyInterpreterState *); | ||
| PyAPI_FUNC(PyThreadState *) PyThreadState_Next(PyThreadState *); | ||
| PyAPI_FUNC(void) PyThreadState_DeleteCurrent(); |
There was a problem hiding this comment.
The prototype must be:
| PyAPI_FUNC(void) PyThreadState_DeleteCurrent(); | |
| PyAPI_FUNC(void) PyThreadState_DeleteCurrent(void); |
Modules/_tracemalloc.c
Outdated
| /* This lock is needed because tracemalloc_free() is called without | ||
| the GIL held from PyMem_RawFree(). It cannot acquire the lock because it | ||
| would introduce a deadlock in _PyThreadState_DeleteCurrent(). */ | ||
| would introduce a deadlock in PyThreadState_DeleteCurrent(). */ |
There was a problem hiding this comment.
I prefer to keep _PyThreadState_DeleteCurrent() here. PyThreadState_DeleteCurrent() is only a public helper function, _PyThreadState_DeleteCurrent() is the real implementation.
Modules/_tracemalloc.c
Outdated
|
|
||
| /* GIL cannot be locked in PyMem_RawFree() because it would introduce | ||
| a deadlock in _PyThreadState_DeleteCurrent(). */ | ||
| a deadlock in PyThreadState_DeleteCurrent(). */ |
There was a problem hiding this comment.
ditto: keep _PyThreadState_DeleteCurrent()
Python/pystate.c
Outdated
| } | ||
|
|
||
| void | ||
| PyThreadState_DeleteCurrent() |
There was a problem hiding this comment.
Please add void to prevent accepting any argument:
| PyThreadState_DeleteCurrent() | |
| PyThreadState_DeleteCurrent(void) |
|
Once this change lands, it would be interested to add an unit test, but I'm not sure how to write such test. C code in _testcapi I guess. |
|
@vstinner , I have addressed the changes. PTAL |
| Destroy the current thread state and release the global interpreter lock. | ||
| Like :c:func:`PyThreadState_Delete`, the global interpreter lock need not | ||
| be held. The thread state must have been reset with a previous call | ||
| to :c:func:`PyThreadState_Clear`. |
There was a problem hiding this comment.
I marked https://bugs.python.org/issue38266 as a release blocker, so the PyThreadState_Clear() question can definitely wait after 3.8.0: we can even revisit this in Python 3.9. Let's stick to adding back the function unmodified.
| PyAPI_FUNC(void) _PyErr_Display(PyObject *file, PyObject *exception, | ||
| PyObject *value, PyObject *tb); | ||
|
|
||
| PyAPI_FUNC(void) _PyThreadState_DeleteCurrent(_PyRuntimeState *runtime); |
There was a problem hiding this comment.
_PyThreadState_DeleteCurrent() has to stay, it's part of https://pythoncapi.readthedocs.io/runtime.html effort to avoid global variables.
| PyAPI_FUNC(void) _PyErr_Display(PyObject *file, PyObject *exception, | ||
| PyObject *value, PyObject *tb); | ||
|
|
||
| PyObject *value, PyObject *tb); |
There was a problem hiding this comment.
nitpick: it seems like you removed a newline or something else. you may revert that.
|
According to https://bugs.python.org/issue38266 discussion, it's a Python 3.8 regression and so this change must be backported to 3.8. I suggest to merge this change into 3.8 and master as soon as possible, to attempt to get it into 3.8.0 final. (But it's ok if we miss the final, it can wait for 3.8.1 otherwise.) |
|
Usually, we let core developers merge their own pull requests. But. Joannah explicitly asked me to merge her PR if I want. Since this change fix a Python 3.8 regression and the next 3.8.0 release (which may be a rc2 or the final) is in 3 days, I prefer to merge it ASAP. |
|
Thanks @nanjekyejoannah for the PR, and @vstinner for merging it 🌮🎉.. I'm working now to backport this PR to: 3.8. |
|
I'm having trouble backporting to |
|
Thanks @nanjekyejoannah for the PR, and @vstinner for merging it 🌮🎉.. I'm working now to backport this PR to: 3.8. |
|
Sorry, @nanjekyejoannah and @vstinner, I could not cleanly backport this to |
|
Thanks @nanjekyejoannah for the PR, and @vstinner for merging it 🌮🎉.. I'm working now to backport this PR to: 3.8. |
|
Sorry, @nanjekyejoannah and @vstinner, I could not cleanly backport this to |
…nal (pythonGH-16558) Revert the removal of PyThreadState_DeleteCurrent() with documentation.
Reverting the removal of
PyThreadState_DeleteCurrent()with documentation.https://bugs.python.org/issue38266