Unload all python modules when modpython is unloaded.

Only user modules were unloaded before.
This commit is contained in:
Alexey Sokolov
2012-01-01 16:46:21 +07:00
parent 0260558155
commit c8a4668bbf
2 changed files with 21 additions and 25 deletions

View File

@@ -320,28 +320,15 @@ public:
}
virtual ~CModPython() {
const map<CString, CUser*>& users = CZNC::Get().GetUserMap();
for (map<CString, CUser*>::const_iterator i = users.begin(); i != users.end(); ++i) {
CModules& M = i->second->GetModules();
bool cont;
do {
cont = false;
for (CModules::iterator it = M.begin(); it != M.end(); ++it) {
CModule* m = *it;
CPyModule* mod = AsPyModule(m);
if (mod) {
cont = true;
bool bSuccess = false;
CString sRetMsg;
OnModuleUnloading(mod, bSuccess, sRetMsg);
if (!bSuccess) {
DEBUG("Error unloading python module in ~CModPython: " << sRetMsg);
}
break;
}
}
} while (cont);
}
PyObject* pyFunc = PyObject_GetAttrString(m_PyZNCModule, "unload_all");
PyObject* pyRes = PyObject_CallFunctionObjArgs(pyFunc, NULL);
if (!pyRes) {
CString sRetMsg = GetPyExceptionStr();
DEBUG("modpython tried to unload all modules in its destructor, but: " << sRetMsg);
}
Py_CLEAR(pyRes);
Py_CLEAR(pyFunc);
Py_CLEAR(m_PyFormatException);
Py_CLEAR(m_PyZNCModule);
Py_Finalize();