-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
bpo-37878: Make PyThreadState_DeleteCurrent() Internal #15315
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @nanjekyejoannah for the PR. I've made some suggested wording changes for reader clarity.
Co-Authored-By: Carol Willing <carolcode@willingconsulting.com>
Co-Authored-By: Carol Willing <carolcode@willingconsulting.com>
@willingc Changes committed. |
Let's give @ericsnowcurrently a chance to review too. Thanks. Please ping me if this is still open later this week and I will merge. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure that it's a good idea to document this function: https://bugs.python.org/issue37878#msg349954
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
@vstinner, I made the function internal instead. PTAL |
Modules/_threadmodule.c
Outdated
@@ -1025,7 +1025,7 @@ t_bootstrap(void *boot_raw) | |||
PyMem_DEL(boot_raw); | |||
tstate->interp->num_threads--; | |||
PyThreadState_Clear(tstate); | |||
PyThreadState_DeleteCurrent(); | |||
_PyThreadState_DeleteCurrent(&_PyRuntime); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add "_PyRuntimeState *runtime = &_PyRuntime;" at the beginning of the function, and replace &_PyRuntime with runtime.
Or maybe even better: add the field to "struct bootstate" and fill the field in thread_PyThread_start_new_thread(). It would make t_bootstrap() more "state-less" (don't access directly global variables).
I dismiss Carol's review since Joannah rewrote her PR, and Carol approved the previous version of the PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since it is a public function, even if it's not documented, please document the removal at:
https://docs.python.org/dev/whatsnew/3.9.html#removed
You can mention that the removed function was not documented.
For example, in Python 3.8, I wrote:
"The PyByteArray_Init() and PyByteArray_Fini() functions have been removed. They did nothing since Python 2.7.4 and Python 3.2.0, were excluded from the limited API (stable ABI), and were not documented. (Contributed by Victor Stinner in bpo-35713.)"
I have made the requested changes; please review again . |
Thanks for making the requested changes! @vstinner: please review the changes made to this pull request. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
Thanks @nanjekyejoannah! It now looks better: remove the function rather than documenting it :-) I prefer to have a smaller C API! |
This breaks pybind 11. Opened an issue with them (pybind/pybind11#1932). Where this should be fixed is a bit over my head at the moment. |
Your gil_scoped_acquire class implementation is scary! Would you mind to open a new issue at bugs.python.org to describe your use case and ask to revert the change which removed PyThreadState_DeleteCurrent? |
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 |
@vstinner: I provided some feedback on the Python bugtracker and here. |
I'm confused by the attached issue; it looks like the decision was to simply revert the change with the function moved, and not add the underscore; and maybe even make it slightly easier to use. Now that 3.9b1 is out, PyBind11-based libraries cannot build, and the only fix would be to start using a now internal function in CPython. SciPy is an example of a PyBind11-using library. |
PyThreadState_DeleteCurrent() is declared by the public C API, but it's now excluded from the limited C API. Does pybind11 uses the limited C API? What is your issue? Please comment https://bugs.python.org/issue37878 instead of this merged PR (if you have a bugs.python.org account). |
I'm sorry, I'll add a bugs.python.org account or see if I had one in the past if I need to comment there. I realize, from looking through the code, that an underscore was not added, the function was moved intact (which was not clear from the PR), exactly as it was supposed to be in the issue. The only remaining problem is that the release notes here are wrong: https://docs.python.org/3.9/whatsnew/3.9.html#removed (which is a much better problem). I'd love it if PyBind11 could use the limited API, but it can't. Thank you, @vstinner ! |
I created #20489 to update the What's New in Python 3.9 document. Would you mind to review my PR? |
Make
PyThreadState_DeleteCurrent()
Internal.https://bugs.python.org/issue37878