docs: show nogil in most examples (#5770)
Created using [mini-swe-agent](https://mini-swe-agent.com) and the propmt:
I'd like to find usages of PYBIND11_MODULE in the docs folder and add py::mod_gil_not_used() as a third argument if there ar
e only two arguments. These are examples, and it's really a good idea to always include that now.
I removed a few of the changes.
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
diff --git a/docs/advanced/cast/custom.rst b/docs/advanced/cast/custom.rst
index 1de0f0a..786192b 100644
--- a/docs/advanced/cast/custom.rst
+++ b/docs/advanced/cast/custom.rst
@@ -108,7 +108,7 @@
} // namespace pybind11
// Bind the negate function
- PYBIND11_MODULE(docs_advanced_cast_custom, m) { m.def("negate", user_space::negate); }
+ PYBIND11_MODULE(docs_advanced_cast_custom, m, py::mod_gil_not_used()) { m.def("negate", user_space::negate); }
.. note::
diff --git a/docs/advanced/cast/functional.rst b/docs/advanced/cast/functional.rst
index d9b4605..c95aa07 100644
--- a/docs/advanced/cast/functional.rst
+++ b/docs/advanced/cast/functional.rst
@@ -56,7 +56,7 @@
#include <pybind11/functional.h>
- PYBIND11_MODULE(example, m) {
+ PYBIND11_MODULE(example, m, py::mod_gil_not_used()) {
m.def("func_arg", &func_arg);
m.def("func_ret", &func_ret);
m.def("func_cpp", &func_cpp);
diff --git a/docs/advanced/classes.rst b/docs/advanced/classes.rst
index 04559d0..14bfc0b 100644
--- a/docs/advanced/classes.rst
+++ b/docs/advanced/classes.rst
@@ -45,7 +45,7 @@
.. code-block:: cpp
- PYBIND11_MODULE(example, m) {
+ PYBIND11_MODULE(example, m, py::mod_gil_not_used()) {
py::class_<Animal>(m, "Animal")
.def("go", &Animal::go);
@@ -112,7 +112,7 @@
.. code-block:: cpp
:emphasize-lines: 2,3
- PYBIND11_MODULE(example, m) {
+ PYBIND11_MODULE(example, m, py::mod_gil_not_used()) {
py::class_<Animal, PyAnimal /* <--- trampoline */, py::smart_holder>(m, "Animal")
.def(py::init<>())
.def("go", &Animal::go);
@@ -774,7 +774,7 @@
#include <pybind11/operators.h>
- PYBIND11_MODULE(example, m) {
+ PYBIND11_MODULE(example, m, py::mod_gil_not_used()) {
py::class_<Vector2>(m, "Vector2")
.def(py::init<float, float>())
.def(py::self + py::self)
diff --git a/docs/advanced/pycpp/numpy.rst b/docs/advanced/pycpp/numpy.rst
index 0c04476..7369dea 100644
--- a/docs/advanced/pycpp/numpy.rst
+++ b/docs/advanced/pycpp/numpy.rst
@@ -217,7 +217,7 @@
};
// ...
- PYBIND11_MODULE(test, m) {
+ PYBIND11_MODULE(test, m, py::mod_gil_not_used()) {
// ...
PYBIND11_NUMPY_DTYPE(A, x, y);
@@ -351,7 +351,7 @@
return result;
}
- PYBIND11_MODULE(test, m) {
+ PYBIND11_MODULE(test, m, py::mod_gil_not_used()) {
m.def("add_arrays", &add_arrays, "Add two NumPy arrays");
}
diff --git a/docs/basics.rst b/docs/basics.rst
index c7a0208..1e68869 100644
--- a/docs/basics.rst
+++ b/docs/basics.rst
@@ -112,7 +112,7 @@
return i + j;
}
- PYBIND11_MODULE(example, m) {
+ PYBIND11_MODULE(example, m, py::mod_gil_not_used()) {
m.doc() = "pybind11 example plugin"; // optional module docstring
m.def("add", &add, "A function that adds two numbers");
@@ -288,7 +288,7 @@
.. code-block:: cpp
- PYBIND11_MODULE(example, m) {
+ PYBIND11_MODULE(example, m, py::mod_gil_not_used()) {
m.attr("the_answer") = 42;
py::object world = py::cast("World");
m.attr("what") = world;
diff --git a/docs/benchmark.py b/docs/benchmark.py
index 26e390e..0b9d08f 100644
--- a/docs/benchmark.py
+++ b/docs/benchmark.py
@@ -33,7 +33,7 @@
result = "#include <pybind11/pybind11.h>\n\n"
result += "namespace py = pybind11;\n\n"
result += decl + "\n"
- result += "PYBIND11_MODULE(example, m) {\n"
+ result += "PYBIND11_MODULE(example, m, py::mod_gil_not_used()) {\n"
result += bindings
result += "}"
return result
diff --git a/docs/benchmark.rst b/docs/benchmark.rst
index 02c2ccd..f1bf321 100644
--- a/docs/benchmark.rst
+++ b/docs/benchmark.rst
@@ -31,7 +31,7 @@
};
...
- PYBIND11_MODULE(example, m) {
+ PYBIND11_MODULE(example, m, py::mod_gil_not_used()) {
...
py::class_<cl034>(m, "cl034")
.def("fn_000", &cl034::fn_000)
diff --git a/docs/classes.rst b/docs/classes.rst
index b126256..97ad72f 100644
--- a/docs/classes.rst
+++ b/docs/classes.rst
@@ -27,7 +27,7 @@
namespace py = pybind11;
- PYBIND11_MODULE(example, m) {
+ PYBIND11_MODULE(example, m, py::mod_gil_not_used()) {
py::class_<Pet>(m, "Pet")
.def(py::init<const std::string &>())
.def("setName", &Pet::setName)
@@ -480,7 +480,7 @@
std::shared_ptr<Child> child;
};
- PYBIND11_MODULE(example, m) {
+ PYBIND11_MODULE(example, m, py::mod_gil_not_used()) {
py::class_<Child, std::shared_ptr<Child>>(m, "Child");
py::class_<Parent, std::shared_ptr<Parent>>(m, "Parent")
diff --git a/docs/faq.rst b/docs/faq.rst
index 31e33f8..2b89d20 100644
--- a/docs/faq.rst
+++ b/docs/faq.rst
@@ -90,7 +90,7 @@
void init_ex2(py::module_ &);
/* ... */
- PYBIND11_MODULE(example, m) {
+ PYBIND11_MODULE(example, m, py::mod_gil_not_used()) {
init_ex1(m);
init_ex2(m);
/* ... */
@@ -235,8 +235,7 @@
.. code-block:: cpp
- PYBIND11_MODULE(example, m)
- {
+ PYBIND11_MODULE(example, m, py::mod_gil_not_used()) {
m.def("long running_func", []()
{
for (;;) {