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

Discussion in 'Python' started by Donnie Leen, Dec 12, 2004.

  1. Donnie Leen

    Donnie Leen Guest

    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
    Donnie Leen, Dec 12, 2004
    1. Advertisements

  2. Donnie Leen

    Donnie Leen Guest

    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
    Donnie Leen, Dec 12, 2004
    1. Advertisements

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Fernando Lopes

    Load an Embbed Resource image

    Fernando Lopes, May 11, 2005, in forum: ASP .Net
    William F. Robertson, Jr.
    May 11, 2005
  2. =?Utf-8?B?UmFlZCBTYXdhbGhh?=

    embbed CAB file in page

    =?Utf-8?B?UmFlZCBTYXdhbGhh?=, Aug 9, 2005, in forum: ASP .Net
    Aug 9, 2005
  3. =?Utf-8?B?QnVkaGkgU2FwdXRyYSBQcmFzZXR5YQ==?=

    Embbed .NET Custom Control (ActiveX) into ASP .NET page

    =?Utf-8?B?QnVkaGkgU2FwdXRyYSBQcmFzZXR5YQ==?=, Sep 13, 2006, in forum: ASP .Net
    Seth Bourne
    Sep 19, 2006
  4. Fernando Lopes

    Load an embbed resource image

    Fernando Lopes, May 11, 2005, in forum: ASP .Net Building Controls
  5. Mazin
    Thomas 'PointedEars' Lahn
    Nov 12, 2003

Share This Page