shared lib from python code?
Gabriel Rossetti
gabriel.rossetti at arimaz.com
Tue Feb 24 09:58:54 EST 2009
Duncan Booth wrote:
> Gabriel Rossetti <gabriel.rossetti at arimaz.com> wrote:
>
>
>> Ok, maybe I mis-stated my problem (or mis-understood your answers).. I
>> don' t want to share code as in have multiple processes access a
>> variable and have the same value, like it is done in threads, what I
>> want is to not have n copies of the code (classes, functions, etc)
>> loaded by n python interpreters. When you load Apache for instance, it
>> runs n processes but loads only one copy of parts of it's code (so/dll),
>> that's what I want to do. In C/C++ I would write a shared-lib (so/dll),
>> so once the system has loaded it, it doesn' t re-load it when another
>> process needs it.
>>
>>
>
> It doesn't matter how you restate it, the answer is still the one Gabriel
> Genellina gave you: Python code objects are not shared between processes.
>
>
Ok, I had though that he had misunderstood me.
> Code objects are immutable, but they are still objects like everything else
> in Python. That means they are reference counted and discarded when no
> longer referenced.
>
> To share code objects between different processes you would have to change
> the reference counting mechanism so it was either safe across multiple
> processes or didn't reference count shared code objects (but still ref
> counted non-shared objects).
>
> The actual code is just stored in a string, so perhaps you could share
> those strings between processes: just executing the code doesn't change the
> string's refcount (whereas it does change the function and the code
> objects' counts). You could probably make something work simply by editing
> the code constructor to move the code into shared memory and using some
> other mechanism to control the shared memory storage.
>
>
Ok, thanks for the explanation.
> C extension libraries on the other hand may be shared.
>
>
Ok, so pyd files must be C extensions then.
Thanks
More information about the Python-list
mailing list