allow reloading of python modules on SIGHUP.

This commit is contained in:
Joris Vink 2017-01-26 11:13:09 +01:00
parent 2c66dfa3cf
commit 1db3cd96d8
1 changed files with 9 additions and 8 deletions

View File

@ -200,19 +200,20 @@ python_module_free(struct kore_module *module)
static void static void
python_module_reload(struct kore_module *module) python_module_reload(struct kore_module *module)
{ {
/* Calls through to kore_python_module_load() below. */ PyObject *handle;
module->fun->load(module, module->onload);
if ((handle = PyImport_ReloadModule(module->handle)) == NULL) {
python_log_error("python_module_reload");
return;
}
Py_DECREF(module->handle);
module->handle = handle;
} }
static void static void
python_module_load(struct kore_module *module, const char *onload) python_module_load(struct kore_module *module, const char *onload)
{ {
if (module->handle != NULL)
Py_DECREF(module->handle);
kore_python_cleanup();
kore_python_init();
module->handle = python_import(module->path); module->handle = python_import(module->path);
if (module->handle == NULL) if (module->handle == NULL)
fatal("%s: failed to import module", module->path); fatal("%s: failed to import module", module->path);