Refreshing Python filters?

Julien ÉLIE julien at
Sun Jun 8 11:10:39 UTC 2008


> I have just tried to play with but I have an issue with
> applying the changes done in this file when reloading it.
> Is there a special thing to do in order to correctly reload a Python filter?
> In fact, I cannot reload it without *stopping* and *restarting* INN!
> I reckon it is a bug...

Oh, reading Python API on reloading:

    Reload a previously imported module.  The argument must be a module object,
    so it must have been successfully imported before.
    There are a number of other caveats:
    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.

I do not understand well what Python exactly does.
What is partially initialized?  "dir(filter_innd)" does not seem to change.

However, what I see is that reloading properly works if I import the Python
module again before reloading it:

Index: innd/python.c
--- innd/python.c       (révision 7859)
+++ innd/python.c       (copie de travail)
@@ -601,6 +601,7 @@

+    PYsetup();
     if ((newmodule = PyImport_ReloadModule(PYFilterModule)) == NULL) {
        syslog(L_ERROR, "cant reload python filter module");

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...

Julien ÉLIE

« Dans l'algèbre comme dans la police, il faut identifier X. » (André Frédérique) 

More information about the inn-workers mailing list