Refreshing Python filters?
Julien ÉLIE
julien at trigofacile.com
Mon Jun 9 18:42:10 UTC 2008
Answering to myself:
>> In fact, I cannot reload it without *stopping* and *restarting* INN!
>> I reckon it is a bug...
>
> Maybe PYsetup() is too much and only a
> PyImport_ImportModule((char *) INN_PATH_PYTHON_STARTUP_M);
> is enough but I do not know whether everything is properly initialized
> by Python afterwards...
Yep, only importing the module again, before reloading it, does the trick.
Now fixed (I hope).
--- python.c 2008-06-09 18:40:30 UTC (rev 7871)
+++ python.c 2008-06-09 18:41:22 UTC (rev 7872)
@@ -618,20 +618,39 @@
Py_XDECREF(result);
}
+ /* We need to reimport the module before reloading it because otherwise,
+ * it might not be taken into account by Python.
+ * See Python API documentation:
+ * If a module is syntactically correct but its initialization fails,
+ * the first import statement for it does not bind its name locally,
+ * but does store a (partially initialized) module object in
+ * sys.modules. To reload the module, you must first import it again
+ * (this will bind the name to the partially initialized module object)
+ * before you can reload() it.
+ */
+ PYFilterModule = PyImport_ImportModule((char *) INN_PATH_PYTHON_STARTUP_M);
+ if (PYFilterModule == NULL) {
+ syslog(L_ERROR, "failed to reimport external python module");
+ }
+
if ((newmodule = PyImport_ReloadModule(PYFilterModule)) == NULL) {
syslog(L_ERROR, "cant reload python filter module");
PYfilter(false);
return 0;
}
+
Py_DECREF(PYFilterModule);
PYFilterModule = newmodule;
+
if (PYFilterObject == NULL) {
syslog(L_ERROR, "python reload error, filter object not defined");
PYfilter(false);
return 0;
}
+
PYfilter(true);
PYdefmethods();
+
return 1;
}
--
Julien ÉLIE
« Vous serez ma bonne légion qu'il disait... » (Astérix)
More information about the inn-workers
mailing list