有 PyMOD(DEINIT)_FUNC 吗?

Is there a PyMOD(DEINIT)_FUNC?

我想知道是否有PyMOD(DEINIT)_FUNC?,我知道当python脚本退出时资源被释放,但我想让我的代码负责内存它尽可能使用。

我当然已经搜索了文档,直到现在我认为卸载模块时没有从 python 核心调用 c 模块的函数,但我希望有,但我只是没有'不知道怎么搜索。

Python 2 不支持模块终结,不支持。见 bug 9072:

Please accept that Python indeed does not support unloading modules for severe, fundamental, insurmountable, technical problems, in 2.x.

对于 Python 3,对用于模块初始化的 C API 进行了大修(请参阅 PEP 3121) and the new PyModuleDef struct has a m_free slot 接受回调函数;使用它来清除模块内存。