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

M

Michael Kohout

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.

Looking at http://docs.python.org/extending/embedding.html#extending-embedded-python,
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?

FYI, I'm embedding python 2.6, but I'm more than open to embedding
something newer.

thanks
Mike Kohout
 
C

Carl Banks

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top