File tree Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -170,6 +170,20 @@ would be then able to access the data behind the same pointer.
170
170
171
171
.. [#f6 ] https://docs.python.org/3/extending/extending.html#using-capsules
172
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));
173
187
174
188
Generating documentation using Sphinx
175
189
=====================================
You can’t perform that action at this time.
0 commit comments