Skip to content

Commit dbf848a

Browse files
authored
docs: extend PYBIND11_MODULE documentation, mention mod_gil_not_used (#5250)
This follows up on PR 5148, which introduced support for free-threaded CPython.
1 parent 43de801 commit dbf848a

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

include/pybind11/detail/common.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,22 @@ PYBIND11_WARNING_POP
462462
return "Hello, World!";
463463
});
464464
}
465+
466+
The third macro argument is optional (available since 2.13.0), and can be used to
467+
mark the extension module as safe to run without the GIL under a free-threaded CPython
468+
interpreter. Passing this argument has no effect on other interpreters.
469+
470+
.. code-block:: cpp
471+
472+
PYBIND11_MODULE(example, m, py::mod_gil_not_used()) {
473+
m.doc() = "pybind11 example module safe to run without the GIL";
474+
475+
// Add bindings here
476+
m.def("foo", []() {
477+
return "Hello, Free-threaded World!";
478+
});
479+
}
480+
465481
\endrst */
466482
#define PYBIND11_MODULE(name, variable, ...) \
467483
static ::pybind11::module_::module_def PYBIND11_CONCAT(pybind11_module_def_, name) \

0 commit comments

Comments
 (0)