[PyKDE] Importing sip-generated module into multiple interpreters

Phil Thompson phil at riverbankcomputing.co.uk
Thu Sep 1 08:20:43 BST 2005


> Hi,
>
> I'm trying to encapsulate a script into
> a seperate Python interpreter.  The idea
> is that these scripts are safely
> isolated from the rest of the system,
> except for our sip-generated "module" API.
>
> 1    Py_BEGIN_ALLOW_THREADS
>
> 2    PyThreadState *pi =  Py_NewInterpreter();
> 3    initsip();
> 4    initmodule();
> 5    PyRun_SimpleString("...");
> 6    Py_EndInterpreter(pi);
>
> 7    Py_END_ALLOW_THREADS
>
> I get the following error in response to line 4,
> perhaps sip isn't designed to deal with multiple
> interpreters?
>
> RuntimeError: the sip module has already registered a module called
> icecore
>
> Any info would be appreciated, especially if
> there is another way to achieve a sandbox sharing
> the same interpreter.

SIP modules should work with multiple interpreters (though it's not
something I test), but (any) module initialisation can only be done once
per process - not once per interpreter.

Phil




More information about the PyQt mailing list