Loading C extension from memory

Martin v. Loewis martin at v.loewis.de
Fri May 14 17:23:06 EDT 2010


> I wonder if there is a way to load C extension from in-memory object,
> not from the file on the disk?
> 
> I'm asking bc I would like to download C extensions over network and
> load them into Python interpreter (without storing the C extension in
> file on the disk).
> 
> I googled for this but there appear only methods of loading compiled
> Python (bytecode) modules.

First, it depends on your operating system. None of the standard
operating systems supports loading shared libraries from memory; they
all need a file name.

Of course, your operating system may provide support for RAM disks. So
if you store the extension onto a RAM disk, you can load it from there -
from memory.

It may be possible to extend the Python interpreter to not rely on
shared libraries anymore for extension modules. Such an interpreter
likely wouldn't use standard shared libraries anymore, so you might
then have to recompile the extensions to make them loadable from memory.
However, it also might be possible to reimplement the shared library
loader of the operating system, in which case you could then run
regular extension modules directly from memory.

Regards,
Martin



More information about the Python-list mailing list