Extending embedded python-can extensions be local to a dictionary?

Carl Banks pavlovevidence at gmail.com
Wed Aug 12 16:57:53 EDT 2009


On Aug 12, 12:44 pm, Michael Kohout <mwkoh... at gmail.com> wrote:
> Hello all-
>
> I've got a multithreaded server-based application that I'd like to use
> python to provide plugin support for.  At execution time I would like
> each call to the plugin/plugins to have their own implementation of
> these extension methods.

I am guessing that what you really want is each call to have its own
data.  There isn't much reason for each call to have its own methods.

If that's not correct you will have to elaborate.


> Looking athttp://docs.python.org/extending/embedding.html#extending-embedded-py...,
> I see how to add functions, but it looks like they are added at a
> global scope-not in a particular environment.  Is there any way to add
> an extension to a local environment but not pollute the global env?

A couple things.  They're not in a global scope, "globals" in Python
have a scope local to a module (global is a misnomer, at best it means
"globally accessible").  So you don't have to worry about a function
defined on one module clashing with a function defined in another
modules.

However, even if name-clashes aren't an issue there isn't much point
to defining the same function mulitple times for multiple calls.

What you probably want is to define a new type that contains all the
data extension code would need.  For each call to the plugin, you
would create an object of this type, then pass it to the appropriate
plugin function.


I have given you a vague answer because your question was vague; if
you want a better answer please rephrase to be more specific.  Include
details like what you would like the code of a Python plugin to look
like.


Carl Banks



More information about the Python-list mailing list