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
Sub-Interpreters : Document PyThreadState_DeleteCurrent() #82059
Comments
I just noticed that PyThreadState_DeleteCurrent()in Python/pystate.c is not documented. Relevant documentation should go in Doc/c-api/init.rst If no one objects to this. |
I'm not sure why PyThreadState_DeleteCurrent() is exposed. Why would anyone use it? It is used internally by the _thread module when the thread function completes. I suggest to make the function internal instead of documenting it. Eric, Joannah: what do you think? |
From what I know the GIL is released by calling PyEval_ReleaseThread() or PyEval_SaveThread(). I see we can use PyThreadState_Delete() to clean up-specifically destroy thread state but does not release the GIL and requires a thread state. On the other hand, PyThreadState_DeleteCurrent() allows to both clean up the current thread state - no thread state is required as well release the GIL which is convenient. I would not fight so much to keep it public given we have PyEval_ReleaseThread() or PyEval_SaveThread(). |
Is it safe to call PyThreadState_DeleteCurrent()? |
I updated the PR to make the function internal. |
I did a GitHub code search on "PyThreadState_DeleteCurrent" in C code: I looked at the first 6 pages: I only found copies of the Python source code, but no *call* to this function. It seems like this function is not used outside Python, so it's fine to remove it. Anyway, if an user complains lately, we can add it back. It's fine. In case of doubt, in this case, I'm fine with removing the function. |
Thanks Joannah. |
Update, Some user of this function just complained on the merged pull requests here : #15315 (comment). Do we revert and deprecate ? cc @victor |
Hi, pybind11 developer here. A bit on context of our usage of this function: Pybind11 supports some advanced GIL-related tricks that require access this function. For instance, pybind11 can intercept a Python function call on the Kind of crazy, but why is this useful? UI libraries. On some platforms, it is not legal to poll UI events on any thread other than the main thread. This means that it's impossible to implement a proper UI event loop because Python is hogging the main thread. With the functionality in pybind11's Best, |
Oh, I didn't notice something in the review: the revert moved PyThreadState_DeleteCurrent() definition from Include/pystate.h to Include/cpython/pystate.h. Previously, it was defined in Include/pystate.h, see the commit removing it: Joannah: can you please move the definition back to Include/pystate.h, at the same place it was before the removal, please? The revert excluded PyThreadState_DeleteCurrent() from the stable API (Py_LIMITED_API). |
To be clear: this issue only impacts Python 3.8. The function was only removed from the master branch. It was still in the 3.8 branch. |
I made this change as it was requested by Eric snow in bpo-38266. "when we un-revert we should be sure to move PyThreadState_DeleteCurrent() from Include/pystate.h to Include/cpython/pystate.h." |
Ah, I didn't see this comment. If Eric endorses this change, I'm fine with it :-) I close the issue. If someone wants to modify PyThreadState_DeleteCurrent() to automatically call PyThreadState_Clear(), please open a new issue for that. |
I was very confused by the history of this issue. To be clear, PyThreadState_DeleteCurrent() is now documented in Python 3.9: |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: