Skip to content

Conversation

@nascheme
Copy link

This is a draft PR. I'll need to make some additional updates before it's ready for review but I thought it's useful to share already.

Summary of changes:

  • Add mechanism to set the Py_MOD_GIL_NOT_USED. I have a patch that does something similar to what pybind11 does: add a variadic macro with an optional flag so extensions can opt-in to free-threaded support
    Replace borrow based APIs with strong reference ones (e.g. PyDict_GetItemRef). That's not included yet and for now Py_MOD_GIL_NOT_USED is always set (makes testing a bit easier).

  • Replace borrow based APIs with strong reference ones (e.g. PyDict_GetItemRef)

  • Use a mutex to protect global state (e.g. the registry). To avoid deadlocks and keep the code simple, there is a single global recursive lock. We can refine this later (split it into the multiple locks, use critical sections, etc).

  • Fix references to ob_refcnt, don't use Py_REFCNT() as an l-value.

  • Ugly work-around for crash in ~object_base(). Needs more investigation for a better fix.

Building this requires a fix to faber. I found building Boost.Python very tricky (likely because I'm not familiar with b2 and faber). I'll share my build scripts in case they help someone else (need to tidy them first).

There is another branch that includes doctests converted to use pytest. I only did a subset of the tests (using Claude to assist in conversion). The goal is to use pytest-run-parallel and try to trigger data races or other issues.

@stefanseefeld
Copy link
Member

stefanseefeld commented Nov 6, 2025

@nascheme I have just pushed a new faber release (0.5.10) including your contributions. Let's see whether they help with this.
(But it seems this needs to be rebased first, to resolve some merge conflicts.)

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.

2 participants