[Cython] Shared Cython runtime

Nikita Nemkin nikita at nemkin.ru
Tue Apr 9 18:30:53 CEST 2013


On Tue, 09 Apr 2013 21:21:25 +0600, Stefan Behnel <stefan_ml at behnel.de>  
wrote:

> Oh, and even simpler, you can just stick multiple Cython modules with  
> their
> module init functions into one big shared library and have the "main"  
> init
> function of that module call the others. That will stick them into
> sys.modules as a side effect, so it's not really different from going
> through Python's import machinery for each module separately (just way  
> more
> efficient - at least if you really need all of the modules...).

That's exactly what I meant.

> There may be glitches with stuff like "__file__" and friends, but that
> should not be any worse than the current way of workings.

I know of two "glitches":

1) Py_InitModule4 expects qualified module name to be provided via
    the _Py_PackageContext global, in order to initialize new module's  
__name__.
    Of course __name__ can also be set manually afterwards.

2) "Top level" init function does not have access to it's own __file__,
    but it has to initialize submodules' __file__ somehow.
    My solution is to query the current shared library name directly
    from the OS (GetModuleFileName() on Windows, dladdr() on everything  
else).

I'm interested in implementing this feature someday. For now, doing it
manually is good enough.


Best regards,
Nikita Nemkin


More information about the cython-devel mailing list