Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions docs/advanced/misc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,26 @@ would be then able to access the data behind the same pointer.
.. [#f6] https://docs.python.org/3/extending/extending.html#using-capsules


Module Destructors
==================

pybind11 does not explicitly provide a mechanism that can be called at module
destruction time (and most users will not need this functionality). However,
if you do happen to need the ability to do something when a module is
destroyed, you can use a Python capsule to accomplish this:

.. code-block:: cpp

// the capsule needs something to reference
static int unused;

py::capsule cleanup(&unused, [](PyObject * capsule) {
// do cleanup here -- this function is called with the GIL held
});

m.add_object("_cleanup", cleanup);


Generating documentation using Sphinx
=====================================

Expand Down