Skip to content

bpo-38266: Revert bpo-37878: Make PyThreadState_DeleteCurrent() Internal #16558

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Oct 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Doc/c-api/init.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1035,6 +1035,14 @@ All of the following functions must be called after :c:func:`Py_Initialize`.
:c:func:`PyThreadState_Clear`.


.. c:function:: void PyThreadState_DeleteCurrent()

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`.
Copy link
Member

Choose a reason for hiding this comment

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

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.

Copy link
Member

Choose a reason for hiding this comment

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

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.



.. c:function:: PY_INT64_T PyInterpreterState_GetID(PyInterpreterState *interp)

Return the interpreter's unique ID. If there was any error in doing
Expand Down
1 change: 1 addition & 0 deletions Include/cpython/pystate.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ PyAPI_FUNC(PyInterpreterState *) PyInterpreterState_Head(void);
PyAPI_FUNC(PyInterpreterState *) PyInterpreterState_Next(PyInterpreterState *);
PyAPI_FUNC(PyThreadState *) PyInterpreterState_ThreadHead(PyInterpreterState *);
PyAPI_FUNC(PyThreadState *) PyThreadState_Next(PyThreadState *);
PyAPI_FUNC(void) PyThreadState_DeleteCurrent(void);

typedef struct _frame *(*PyThreadFrameGetter)(PyThreadState *self_);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Revert the removal of PyThreadState_DeleteCurrent() with documentation.
10 changes: 8 additions & 2 deletions Python/pystate.c
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,7 @@ PyThreadState_Clear(PyThreadState *tstate)
}


/* Common code for PyThreadState_Delete() and _PyThreadState_DeleteCurrent() */
/* Common code for PyThreadState_Delete() and PyThreadState_DeleteCurrent() */
static void
tstate_delete_common(_PyRuntimeState *runtime, PyThreadState *tstate)
{
Expand Down Expand Up @@ -863,7 +863,7 @@ _PyThreadState_DeleteCurrent(_PyRuntimeState *runtime)
PyThreadState *tstate = _PyRuntimeGILState_GetThreadState(gilstate);
if (tstate == NULL)
Py_FatalError(
"_PyThreadState_DeleteCurrent: no current tstate");
"PyThreadState_DeleteCurrent: no current tstate");
tstate_delete_common(runtime, tstate);
if (gilstate->autoInterpreterState &&
PyThread_tss_get(&gilstate->autoTSSkey) == tstate)
Expand All @@ -874,6 +874,12 @@ _PyThreadState_DeleteCurrent(_PyRuntimeState *runtime)
PyEval_ReleaseLock();
}

void
PyThreadState_DeleteCurrent(void)
{
_PyThreadState_DeleteCurrent(&_PyRuntime);
}


/*
* Delete all thread states except the one passed as argument.
Expand Down