shared lib from python code?
gabriel.rossetti at arimaz.com
Tue Feb 24 09:56:59 EST 2009
andrew cooke wrote:
> Gabriel Rossetti 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.
> i think i understand what you want. the problem is that the kind of
> language that python is really doesn't work well with that kind of
> approach. this is (and i may be wrong - i've not really thought much
> about this before) largely because python places a very strong emphasis on
> late binding. that means that everything is very flexible - all kinds of
> things can be changed "under the hood". and that means that it is very
> difficult to share things safely because almost any solution would end up
> doing what you don't want (sharing variables, like with threads (even
> though they are very deeply buried variables)) rather than what you do
> want (just sharing the static part of the code to save space).
> another way to see this is to see the connection with security. this is
> the flip side of your case - because things are so flexible it is very
> hard to run some python code in a "sandbox" in a larger python program.
> there's some discussion on the dev group at the moment and it looks like
> the solution is to only use function closures. but even that doesn't work
> without some patches that remove certain ways to dynamically alter the
> code base.
Ok, I see, thank you. I thought this was possible since I have used
*.pyd files before and from what I had read they were dynamic library
files. I guess they must be written in C/C++ then. Thank you for the
More information about the Python-list