PyThreadState_DeleteCurrent()

Tim Peters tim.one at comcast.net
Wed Mar 27 02:27:54 EST 2002


[Geoff Gerrietts]
> ...
> But ... what's the difference? When is PyThreadState_DeleteCurrent()
> the appropriate call, and when PyThreadState_Delete()? I've looked,
> and the docs haven't been updated to reflect this API change.

PyThreadState_Delete(PyThreadState *tstate) can only be called when the
passed-in tstate is not the current thread state.  It doesn't matter whether
you hold the GIL when it's called.

PyThreadState_DeleteCurrent() takes no argument, and deletes the current
thread state.  You must hold the GIL while calling it, and the thread
calling it loses its tstate, and loses the GIL, and must never call anything
in the Python C API ever again (unless it acquires another tstate first, but
that's an intended use case).  As that description hints <wink>, it was
introduced to plug a Python shutdown race.

A detailed explanation of "the bug" can be found in the comments here:

    http://www.python.org/sf/225673





More information about the Python-list mailing list