We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 0c99402 commit c053462Copy full SHA for c053462
docs/advanced/misc.rst
@@ -170,6 +170,20 @@ would be then able to access the data behind the same pointer.
170
171
.. [#f6] https://docs.python.org/3/extending/extending.html#using-capsules
172
173
+Module Destructors
174
+==================
175
+
176
+pybind11 does not provide an explicit mechanism to invoke cleanup code at
177
+module destruction time. In rare cases where such functionality is required, it
178
+is possible to emulate it using Python capsules with a destruction callback.
179
180
+.. code-block:: cpp
181
182
+ auto cleanup_callback = []() {
183
+ // perform cleanup here -- this function is called with the GIL held
184
+ };
185
186
+ m.add_object("_cleanup", py::capsule(cleanup_callback));
187
188
Generating documentation using Sphinx
189
=====================================
0 commit comments