What's the proper way to clean up static python object references in a CPython extension module?

StackOverflow https://stackoverflow.com/questions/15688954

Вопрос

The CPython headers define a macro to declare a method that is run to initialize your module on import: PyMODINIT_FUNC

My initializer creates references to other python objects, what is the best way to ensure that these objects are properly cleaned up / dereferenced when my module is unloaded?

Это было полезно?

Решение

You can't unload C extension modules at all. There is just no way to do it, and I know for sure that most of the standard extension modules would leak like crazy if there was.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top