[pypy-dev] prevent extension module code from being executed during startup?

wlavrijsen at lbl.gov wlavrijsen at lbl.gov
Fri Mar 29 21:14:14 CET 2013


Hi,

when starting pypy-c, I get some extension module code executed before that
module is imported.

The code in question is in pypy/module/cppyy/pythonify.py:

gbl = make_cppnamespace(None, "::", None, False)   # global C++ namespace
gbl.__doc__ = "Global C++ namespace."
sys.modules['cppyy.gbl'] = gbl

This code is not rpython code. The module is first mentioned in the
__init__.py of cppyy:

     appleveldefs = {
         'gbl'                    : 'pythonify.gbl',
         'load_reflection_info'   : 'pythonify.load_reflection_info',
         'add_pythonization'      : 'pythonify.add_pythonization',
     }

How can I prevent that code from being executed at startup, i.e. have it
deferred all the way until "import cppyy"?

The use case is as follows: I have a prototype where I load the Reflex
library (and associated C-API) at run-time, using _cffi_backend. That way,
it is no longer necessary to link pypy-c with libReflex.so. I can handle a
missing .so silently, but would prefer to raise an ImportError. However,
for that to work, I need to make sure nothing of the module gets touched
until it's imported, so that the error is reported at the right time.

Thanks,
      Wim
-- 
WLavrijsen at lbl.gov    --    +1 (510) 486 6411    --    www.lavrijsen.net


More information about the pypy-dev mailing list