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

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

Question

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?

Était-ce utile?

La solution

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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top