Skip to content

Let pybind11 modules release the GIL when used with free-threaded Python - #216

Open
sebp wants to merge 1 commit into
osqp:masterfrom
sebp:enable-free-threading
Open

Let pybind11 modules release the GIL when used with free-threaded Python#216
sebp wants to merge 1 commit into
osqp:masterfrom
sebp:enable-free-threading

Conversation

@sebp

@sebp sebp commented Aug 13, 2026

Copy link
Copy Markdown

While free-threading wheels are being built, the pybind11 modules currently do not release the GIL. Therefore, when running osqp with free-threaded Python, one gets the warning:

<frozen importlib._bootstrap>:491: RuntimeWarning: The global interpreter lock (GIL) has been enabled to load module 'osqp.ext_builtin', which has not declared that it can run safely without the GIL. To override this behavior and keep the GIL disabled (at your own risk), run with PYTHON_GIL=0 or -Xgil=0.

This pull request releases the GIL, based on https://pybind11.readthedocs.io/en/stable/advanced/misc.html#free-threading-support

Minimum required version for dependencies have been raised to versions that added support for free-threaded Python when using Python 3.14 or later.

Raise minimum required version for dependencies that
added support for free-threaded Python when using Python 3.14
or later.
@CLAassistant

CLAassistant commented Aug 13, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@vineetbansal

Copy link
Copy Markdown
Contributor

@sebp - the osqp C++ bindings for python are not thread-safe though, so I'm fairly certain that we do need to hold the GIL. Do you have evidence to the contrary?

@sebp

sebp commented Aug 13, 2026

Copy link
Copy Markdown
Author

@vineetbansal I do not have evidence that the C++ code is thread-safe. I would consider this PR as an experiment to provide free-threaded wheels so that thread-safety can be evaluated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants