WIP: Add runtime selection of GIL implementation #1322
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #1276.
Example usage:
The
select_gil_impl()call notifies pybind that this particular program requires thebasic_gil_implimplementation. If another executable or library has already calledselect_gil_impl()with a different, incompatible implementation, an exception is thrown. If no library or executable ever callsselect_gil_impl(), thebasic_gil_implis used by default. (Whether we should use basic or advanced by default is an ongoing discussion. I personally am in favor of basic being the default.)If we want to use the advanced API with the thread disassociation feature:
advanced_gil_impldoesn't currently do any checks to see ifbasic_gil_implhas already been used. That has been left up to thegil_scoped_releaseinternals.Important note: this PR does introduce two incompatible changes requiring a major version update:
gil_scoped_releasewith the boolean disassociation flag. You have to useadvanced_gil_impl::releaseinstead. We can certainly do some shuffling of names such thatgil_scoped_acquireandgil_scoped_releaseserve as typedefs of the advanced API, and then the "real" API would be something likeauto_gil_scoped_acquireandauto_gil_scoped_release.This is the first draft of a WIP. It should serve as a good first sketch of what we want this to look like. Comments welcome, I look forward to hearing your feedback.