471,309 Members | 1,622 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,309 software developers and data experts.

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

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
Jul 18 '05 #1
1 2763
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
Jul 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Bren | last post: by
reply views Thread by Gouda Man | last post: by
reply views Thread by Li Daobing | last post: by
5 posts views Thread by maggie.nguyen | last post: by
4 posts views Thread by Shawn McGrath | last post: by
6 posts views Thread by Soren | last post: by
reply views Thread by Ling | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.