problem with embbed boost.python in multi-interpreter andmulti-thread HELP please

D

Donnie Leen

I wrote a program embbed boost.python, each thread running a sub-interpreter, i made a module implement by boost.python, and i wish this module imported in each sub-interpreter, i find that the module could initialize only once, otherwise the boost.python will throw a exception said that something already registered; second conversion method ignored.

So I try another way, initialize and import the module in one interpreter such as the main interpreter, and I hope to import the module in any sub-interpreter, because I found the python document said:
"Extension modules are shared between (sub-)interpreters as follows: the first time a particular extension is imported, it is initialized normally, and a (shallow) copy of its module's dictionary is squirreled away. When the same extension is imported by another (sub-)interpreter, a new module is initialized and filled with the contents of this copy; the extension's init function is not called. "
but when i try this way i found that the program throw an exception:ImportError: No module named mym, (mym is the module name). This happens even i wrote the module in Python/C API without boost.python.

Could somebody tell me why this happened or how to deal with it, thanks for any suggestion.

Donnie Leen
 
D

Donnie Leen

All right, I found the answer in boost.python test example embedding.cpp,
not to call initmodulename() in every sub-interpreter, just call
PyImport_AppendInittab("modulename", initmodulename) before call to
Py_Initialize(), this will add the module to the interpreter's builtin
modules, then I can call "import modulenmame" in each sub-interpeter.

Donnie Leen
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top