[omniORB] Problem with embedded Python

Duncan Grisby duncan at grisby.org
Thu Jan 8 15:45:23 GMT 2004


On Monday 5 January, "Andrew Midson" wrote:

> We have Python 2.2 embedded in a C++ application. Python is initialised when
> the application starts and then, for each script run from the application,
> an interpreter is created, the script is run and the interpreter is
> destroyed. We can use ominORBpy in scripts run from this application as long
> as we only run one such script. If a second omniORBpy script is run without
> closing the application and restarting it, we get the following import
> error:
> 
> ImportError: No module named omni_func

The problem is that the _omnipy module initialises a number of
sub-modules when it is imported. Python only imports extension modules
once, as long as the interpreter exists. Stopping your program and
restarting it is clearing out sys.modules, and nothing ever puts the
_omnipy submodules back in.

Do you really need to destroy the interpreter but not finalize Python?
If you are able to keep the interpreter you won't have this problem.

If you have no other option, I expect you can get it to work by adding
a new function to the omniORBpy C++ API (in include/omniORBpy.h and
modules/cxxAPI.cc) that reinitialises the submodules. You would need
to lift the relevant code from omnipy.cc's init_omnipy() function. I
haven't tried this, but I think it should work.

Cheers,

Duncan.

-- 
 -- Duncan Grisby         --
  -- duncan at grisby.org     --
   -- http://www.grisby.org --



More information about the omniORB-list mailing list