How to know if the refcount of any object in python is not 0 when the interpreter is closed?

0

I created a module and a submodule with CPython in which I put a dubious Py_INCREF(submodule); . The code is this:

PyDoc_STRVAR(MEU_modulo_doc,
"Esse eh meu modulo.\n"
);
static struct PyModuleDef MEU_modulo_def = {
    PyModuleDef_HEAD_INIT,
    .m_name = "meu_modulo",
    .m_doc = MEU_modulo_doc,
};

PyDoc_STRVAR(MEU_SUBmodulo_doc,
"Esse eh meu SUB modulo.\n"
);
static struct PyModuleDef MEU_SUBmodulo_def = {
    PyModuleDef_HEAD_INIT,
    .m_name = "meu_modulo.meu_submodulo",
    .m_doc = MEU_SUBmodulo_doc,
};

PyObject *PyInit_meu_modulo(void)
{
    PyObject *sys_modules = PyImport_GetModuleDict();
    PyObject *submodule;
    PyObject *mod;

    mod = PyModule_Create(&MEU_modulo_def);
    submodule = PyModule_Create(&MEU_SUBmodulo_def);

    PyModule_AddObject(mod, "meu_submodulo", submodule);
    PyDict_SetItem(sys_modules, PyModule_GetNameObject(submodule), submodule);
    Py_INCREF(submodule); /* Esse INCREF eh realmente necessario??? */

    return mod;
}

My big question is that Py_INCREF(submodule); . How do I know if this call is needed? How to tell if the module was and needs to be deallocated when closing the interpreter?

    
asked by anonymous 14.09.2018 / 19:50

0 answers